用于数据收集的强大Python包装器over Etherscan API。

etherscan-p的Python项目详细描述


用于数据收集的强大Python包装器over Etherscan API。在

说明

Etherscan API在端点之间存在各种不一致性,例如值的编码(十六进制与base10)以及返回的数据结构。该模块简化并标准化了从Etherscan返回的数据结构,并提供了性能改进,如查询中的并行化。在

安装

要安装软件包,只需运行以下命令:

pip install etherscan_py

使用

要使用该包,请使用您的Etherscan API密钥初始化客户端。在

^{pr2}$

数据结构

基本的Etherscan事件数据结构。在

class EtherscanEvent:
    address: string
    topics: [string]
    data: string
    block_height: int
    timestamp: int
    gas_price: int
    gas_used: int
    logindex: int
    txhash: string

基本的Etherscan事件数据结构,以及导致事件发出的关联事务的附加信息。在

class EnrichedEvent(EtherscanEvent):
    address: string
    topics: [string]
    data: string
    block_height: int
    timestamp: int
    gas_price: int
    gas_used: int
    logindex: int
    txhash: string
    from_address: string
    to_address: string
    tx_input: string
    nonce: int
    position_in_block: int
    value: int

基本的Etherscan事务数据结构。在

class EtherscanTransaction:
    txhash: string
    block_height: int
    timestamp: int
    nonce: int
    from_address: string
    to_address: string
    value: int
    gas_price: int
    tx_input: string
    position_in_block: int
    is_error: bool

方法

以下是支持的方法:

  1. {1}$ .. 代码块:

    >>> client.get_eth_price()
    >>> 229.16
    
  2. get_latest_block_height() .. 代码块:

    >>> client.get_latest_block_height()
    >>> 10309928
    
  3. get_first_tx_block(address) .. 代码块:

    >>> client.get_first_tx_block('0x27054b13b1B798B345b591a4d22e6562d47eA75a')
    >>> 4352086
    
  4. get_tx_by_hash(txhash) .. 代码块:

    >>> res = client.get_tx_by_hash('0xb8b56002413bb6b8a0fbf7f986715a297d678ecfc4fdcd0b37d9a88048e5c68e')
    >>> res.txhash
    >>> '0xb8b56002413bb6b8a0fbf7f986715a297d678ecfc4fdcd0b37d9a88048e5c68e'
    
  5. get_all_events(address, topic, enriched_data=False, from_block=0, to_block='latest', thread_count=1)

    >>> res = client.get_all_events(
        address = '0x51c72befae54d365a9d0c08c486aee4f99285e08',
        topic = '0x56f54e5e291f84831023c9ddf34fe42973dae320af11193db2b5f7af27719ba6'
    )
    >>> len(res)
    >>> 72
    
  6. get_all_transactions(from_address, status, to_address='',fn_signature='', from_block=0, to_block='latest', thread_count=1)

    status is either 0,1 or 2.

       0: Failed
       1: Successful
       2: Both
    
    
    fn_signature is the first 10-characters of a tx's input_data
    
    >>> res = client.get_all_transactions(
        from_address = '0x274CeA454c35b6bB3fE07377E719e45dF9E3Cac6',
        status = 2,
        to_address = '0x51c72befae54d365a9d0c08c486aee4f99285e08'
    )
    >>> len(res)
    >>> 14
    

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

推荐PyPI第三方库


热门话题
我可以用C++代码使用java代码吗?   java使用JSR303在派生类中提供更具体的约束   java在这个查找唯一路径数算法中我做错了什么?   java如何为2个不同的服务提供商使用2个不同的SSL证书?   java在Gridview上绘制文本   java使用连接for循环构建字符串名   java StringBuilder拆分无法处理某些文件   java事件关注EditText   Java Web Start“找不到URL的缓存资源”   java程序从命令行运行的速度比在Eclipse中慢   java为什么HttpServletRequest会截断#字符上的url输入?   java自定义折叠工具栏平滑标题大小调整   使用Mockito对安卓 java中调用另一个静态函数的函数进行单元测试   http在java客户机中使用cachecontrol头   java如何使用。是否使用Delimiter从输入文件中排除标点符号和数字?   使用上下文作为参数/参数的java   java更有效地从Jar中提取文件   java为多个JButton提供相同的actionListener