# Aave gho稳定币项目的存款交互 **Published by:** [junjie9021](https://paragraph.com/@junjie9021-3/) **Published on:** 2023-02-25 **URL:** https://paragraph.com/@junjie9021-3/aave-gho ## Content aave在Goerli测试网络上推出了自家的Gho稳定币项目,支持存款,借贷,还款等交互。Aave - Open Source Liquidity ProtocolAave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.https://gho.aave.com我们用代码的方式来交互下存款,python3代码样例,可执行代码:注意: 执行前记得替换自己的私钥,默认存款0.01个""" pip3 install web3 """ import web3 import math import requests headers = { 'content-type': 'application/json', 'accept-encoding': 'gzip, deflate, br', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, rpc='https://rpc.ankr.com/eth_goerli', chainid=5, proxies=None, timeout=30): self.rpc = rpc self.chainid = chainid self.proxies = proxies self.timeout = timeout def get_transaction(self, txhash): """获取的交易详情""" data = {"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":[txhash],"id":1} res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout) return res.json() def get_gas_price(self): """获取gas""" data = {"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1} res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout) return res.json() def get_balance(self, address): """获取余额""" data = {"jsonrpc":"2.0","method":"eth_getBalance","params":[address, 'latest'],"id":1} res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout) return res.json() def get_transaction_count_by_address(self, address): """获取地址nonce""" data = {"jsonrpc":"2.0","method":"eth_getTransactionCount","params":[address,'latest'],"id":1} res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout) return res.json() def send_raw_transaction(self, hex): """广播交易""" data = {"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":[hex],"id":1} res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout) return res.json() def transfer(self, account, to, amount, gaslimit, **kw): """离线交易 account to: 收款地址 gaslimit: 由当前区块的gaslimit获取 gasprice: get_gas_price获取 nonce: 交易总数 get_transaction_count_by_address获取 chainId: 链id """ amount = int(amount, 16) if isinstance(amount, str) else int(amount) gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit gasprice = int(self.get_gas_price()['result'], 16) nonce = int(self.get_transaction_count_by_address(account.address)['result'], 16) tx = {'from': account.address, 'value': amount,'to': to, 'gas': gaslimit, 'gasPrice': gasprice, 'nonce': nonce, 'chainId': self.chainid} if kw: tx.update(**kw) signed = account.signTransaction(tx) return self.send_raw_transaction(signed.rawTransaction.hex()) if __name__ == '__main__': privkey = 'xxxxxxx' # 这里替换成自己的私钥 account = web3.Account.from_key(privkey) rpc = Rpc() value = 0.01 # 要存款的数量 gaslimit = 299906 # gaslimit to = '0x9c402e3b0d123323f0fced781b8184ec7e02dd31' # base存款的合约地址 method = '0x474cf53d' # 存款方法hash值 amount = int(value * math.pow(10, 18)) # eth的主币精度是18位 unit_0 = '000000000000000000000000617cf26407193e32a771264fb5e9b8f09715cdfb' addr_1 = account.address[2:].rjust(64,'0') # 地址格式处理 unit_2 = '0000000000000000000000000000000000000000000000000000000000000000' data = method + unit_0 + addr_1 + unit_2 # 拼接数据 res = rpc.transfer(account, to=to, amount=amount, gaslimit=gaslimit, data=data) # 发送交易 print(res) 执行后打印交易hash, 去浏览器查询状态 https://goerli.etherscan.io/回到gho dashbord,看到我们已经地址已经有存款了Aave - Open Source Liquidity ProtocolAave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.https://gho.aave.com代码样例已上传:simple-airdrop-demo/aave at main · junjie9021/simple-airdrop-demoContribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.https://github.com ## Publication Information - [junjie9021](https://paragraph.com/@junjie9021-3/): Publication homepage - [All Posts](https://paragraph.com/@junjie9021-3/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@junjie9021-3): Subscribe to updates