轻量级模块,获得以太坊和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仅在findViewById()下显示一个ImageButton   在Java Graphics2D中,文本如何在矩形上居中对齐?   java需要一个用于电子表格计算器的正则表达式   ^java中的运算符   java通过一些属性配置文件根据环境动态更改wsdl端点URL   java Ebean/Play框架关系未更新   集合如何将POJO列表转换为Java流中的映射<String,List>?   java为什么JFrame不显示整个图像?   java如何将调用静态导入的泛型方法的结果传递给另一个方法?   迭代器或foreach中的java延迟   需要java socket logback日志接收器   在Java中初始化Map的静态数组   雅加达邮件Java MimeMail:解码后获得额外字符   java为什么这个xmldom解析器不能正确解析rtept、name和cmt标记?   java如何刷新Log4J2中的异步记录器(带中断器)   java使用构建插件pom生成的jar。xml作为同一pom中的依赖项   java基于位置的序列ADT如何在O(1)时间内插入元素?   java ORM实体与DDD实体   Java对象分配