轻量级模块,获得以太坊和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版

新的

  • 第一个工作版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将变量从一个类发送到另一个类   使用Java Kubernetes客户端Api部署pod   sql如何从oracle检索图像并在java框架中显示   java更改Clover检测类的位置   java安卓位置。getAccuracy()返回1   运行时。不支持Java ME 8上的exec()。还有别的选择吗?   bdd在Java中运行Cucumber时修改CucumberOptions标记   在java中将方法更改为运行时异常   构造函数类中的Java NullPointerException   java SetResizeable(false)不会阻止双击后的帧还原   java智能卡终端移除:SCARD_E_无服务卡例外   Java正则表达式和组   爪哇骑士巡回赛   端口8443上通过ssl的java Spring安全登录在使用http协议的端口8080上无法识别   java如何确定读取文件的哪一行特定行