Etherscan API中文手册

账号API
account - 以太坊账号API模块 account/balance - 获取指定地址的余额 account/balancemulti - 获取多个地址的余额 account/txlist - 获取指定地址的普通交易 account/txlistinternal - 获取指定地址的内部交易 account/txlistinternal - 获取指定交易触发的内部交易 account/tokentx - 获取指定地址的ERC20代币转账交易 account/getminedblock - 获取指定地址挖出的区块
合约API
contract - 智能合约API模块 contract/getabi - 获取指定合约的ABI contract/getcode - 获取指定合约的源代码 contract/verifysourcecode - 验证指定合约的源代码 contract/checkverifystatus - 获取源代码验证结果
交易API
transaction - 交易API模块 transaction/getstatus - 获取指定交易的执行状态 transaction/gettxreceiptstatus - 获取指定交易的收据状态
区块API
block - 区块API模块 block/getblockreward - 获取指定区块奖励额
事件日志API
logs - 日志API模块 logs/getLogs - 获取以太坊日志
节点代理API
proxy - 节点代理API模块 proxy/eth_blockNumber - 获取链头区块编号 proxy/eth_getBlockByNumber - 获取指定编号的区块详情 proxy/eth_getUncleByBlockNumberAndIndex - 获取指定的叔伯区块详情 proxy/eth_getBlockTransactionCountByNumber - 获取指定编号区块的交易数量 proxy/eth_getTransactionByHash - 获取指定哈希交易的详情 proxy/eth_getTransactionByBlockNumberAndIndex - 获取指定区块及序号交易的详情 proxy/eth_getTransactionCount - 获取指定地址发生的交易数量 proxy/eth_sendRawTransaction - 发送裸交易 proxy/eth_getTransactionReceipt - 获取指定交易的收据 proxy/eth_call - 执行消息调用 proxy/eth_getCode - 获取指定地址的代码 proxy/eth_getStorageAt - 获取指定位置的内容 proxy/eth_gasPrice - 获取当前的gas价格 proxy/eth_estimateGas - 估算交易gas用量
通证/代币API
token - 代币API概述 stats/tokensupply - 获取指定ERC20代币的总供应量 account/tokenbalance - 获取指定账号的ERC20代币余额
统计API
stats - 统计API模块 stats/ethsupply - 获取以太币当前总量 stats/ethprice - 获取以太币最新价格 stats/chainsize - 获取节点数据大小
开发包
Etherscan开发包
在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

logs/getLogs - 获取以太坊日志

使用logs模块的getLogs方法获取以太坊日志。

API调用

GET|POST /api

查询|表单参数:

  • module:logs
  • action:getLogs
  • fromBlock:起始区块
  • toBlock:结束区块
  • address:要获取日志的合约地址
  • topic0:日志主题0
  • topic1:日志主题1
  • topic2:日志主题2
  • topic3:日志主题3
  • topic0_1_opr:主题0和主题1的操作符,and - 与, or - 或
  • topic1_2_opr:主题1和主题2的操作符,同上
  • topic2_3_opr:主题2和主题3的操作符,同上
  • topic0_2_opr:主题0和主题2的操作符,同上
  • topic0_3_opr:主题0和主题3的操作符,同上
  • topic1_3_opr:主题1和主题3的操作符,同上

API返回值

返回结果为一个JSON对象,主要字段如下:

  • status:状态码,1为成功
  • message:调用描述信息,OK为成功
  • result:调用结果为事件日志数组,每个成员包含如下字段:
    • address:发生事件的合约地址
    • topics:事件的主题
    • data:事件额外的数据
    • blockNumber:区块编号
    • timeStamp:时间戳
    • gasUsed:消耗的gas
    • logIndex:日志索引
    • transactionHash:交易哈希
    • transactionIndex:交易索引

示例代码

下面的curl命令获取从 379224#区块到最新区块之间,合约 0x33990122638b9132ca29c723bdf037f1a891a70c发生的主题0为 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545的日志:

~$ curl https://api.etherscan.io/api?module=logs&action=getLogs&fromBlock=379224&toBlock=latest&address=0x33990122638b9132ca29c723bdf037f1a891a70c&topic0=0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545 &apikey=YourApiKeyToken

返回值:

{
  "status": "1",
  "message": "OK",
  "result": [
    {
      "address": "0x33990122638b9132ca29c723bdf037f1a891a70c",
      "topics": [
        "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545",
        "0x72657075746174696f6e00000000000000000000000000000000000000000000",
        "0x000000000000000000000000d9b2f59f3b5c7b3c67047d2f03c3e8052470be92"
      ],
      "data": "0x",
      "blockNumber": "0x5c958",
      "timeStamp": "0x561d688c",
      "gasPrice": "0xba43b7400",
      "gasUsed": "0x10682",
      "logIndex": "0x",
      "transactionHash": "0x0b03498648ae2da924f961dda00dc6bb0a8df15519262b7e012b7d67f4bb7e83",
      "transactionIndex": "0x"
    },
    ...
  ]
}

下面的curl命令获取379224~400000区块范围内,合约0x33990122638b9132ca29c723bdf037f1a891a70c发生的主题0为 0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545并且主题1为0x72657075746174696f6e00000000000000000000000000000000000000000000 的事件:

~$ curl https://api.etherscan.io/api?module=logs&action=getLogs&fromBlock=379224&toBlock=400000&address=0x33990122638b9132ca29c723bdf037f1a891a70c&topic0=0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545&topic0_1_opr=and&topic1=0x72657075746174696f6e00000000000000000000000000000000000000000000&apikey=YourApiKeyToken

返回值:

{
  "status": "1",
  "message": "OK",
  "result": [
    {
      "address": "0x33990122638b9132ca29c723bdf037f1a891a70c",
      "topics": [
        "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545",
        "0x72657075746174696f6e00000000000000000000000000000000000000000000",
        "0x000000000000000000000000d9b2f59f3b5c7b3c67047d2f03c3e8052470be92"
      ],
      "data": "0x",
      "blockNumber": "0x5c958",
      "timeStamp": "0x561d688c",
      "gasPrice": "0xba43b7400",
      "gasUsed": "0x10682",
      "logIndex": "0x",
      "transactionHash": "0x0b03498648ae2da924f961dda00dc6bb0a8df15519262b7e012b7d67f4bb7e83",
      "transactionIndex": "0x"
    }
  ]
}