轻量级模块,获得以太坊和ERC20代币余额
pyetherbalance的Python项目详细描述
pyetherbalance
pyetherbalance
是一个python模块,用于获取以太坊和er20令牌余额。还有其他模块,如web3py,但这个模块的目标是超轻重量,不依赖于太多其他模块。
安装
只需克隆项目并运行python setup.py install
-或通过pip pip install pyetherbalance
安装。
此模块仅依赖于python中的“requests”库来发送post请求
基本用法:
importpyetherbalance# Sign up for https://infura.io/, and get the url to an ethereum nodeinfura_url='https://mainnet.infura.543254324532543254345'ethereum_address='0xeb9f035dd1211af75976427d68d2d6dc549c458e'# Create an pyetherbalance object , pass the infura_urlethbalance=pyetherbalance.PyEtherBalance(infura_url)# get ether balancebalance_eth=ethbalance.get_eth_balance(ethereum_address)print(balance_eth)# get token balance balance_omg=ethbalance.get_token_balance('OMG',ethereum_address)print(balance_omg)
高级用法:
添加标记
当前模块使用https://github.com/ethereum-lists/tokens作为标记列表。如果要添加自己的自定义标记,可以按照以下步骤进行操作。这也适用于覆盖内部令牌协定地址。
importpyetherbalance# Sign up for https://infura.io/, and get the url to an ethereum nodeinfura_url='https://mainnet.infura.543254324532543254345'ethereum_address='0xeb9f035dd1211af75976427d68d2d6dc549c458e'# Create an pyetherbalance object , pass the infura_urlethbalance=pyetherbalance.PyEtherBalance(infura_url)# New token symboltoken="OMG"# Token details. The fields below are all requireddetails={'symbol':'OMG','address':'0xd26114cd6EE289AccF82350c8d8487fedB8A0C07','decimals':18,'name':'OmiseGO'}# Add token erc20tokens=ethbalance.add_token(token,details)# print list of all internal tokensprint(erc20tokens['OMG'])
获取所有令牌:
importpyetherbalance# Sign up for https://infura.io/, and get the url to an ethereum nodeinfura_url='https://mainnet.infura.543254324532543254345'# Create an pyetherbalance object , pass the infura_urlethbalance=pyetherbalance.PyEtherBalance(infura_url)# Get a dictionary with all tokens and details erc20tokens=ethbalance.get_erc20_tokens()print(erc20tokens)
测试:
测试您可以在初始化PyetherBalance对象时,通过提供相应以太坊节点的URL,在Ropsten、Kovan、Rinkeby或本地测试网络上进行测试。
版权所有
MTI许可证-有关详细信息,请参阅许可证。
更改日志
0.0.1版
新的
- 第一个工作版本