美文网首页区块链研习社互联网科技区块链
Etherscan API 按地址查询内部交易 - 区块链数据开

Etherscan API 按地址查询内部交易 - 区块链数据开

作者: 极客红石 | 来源:发表于2019-03-27 21:18 被阅读28次

    简介:Etherscan 大多数朋友都比较熟悉了,它是主流以太坊区块浏览器。Etherscan 有面向开发者提供 API 服务以方便其检索以太坊区块链信息。本文示例如何使用 Etherscan API 按地址查询以太坊内部交易(Internal Transactions)。

    Etherscan 大多数朋友都比较熟悉了,它是主流以太坊区块浏览器。Etherscan 有面向开发者提供 API 服务以方便其检索以太坊区块链信息。

    Etherscan API 在没有密钥的情况下,支持每秒最多五次请求。有更多请求需求可以在这里申请密钥:https://etherscancom.freshdesk.com/support/solutions/articles/35000022163-i-need-an-api-key

    使用 Etherscan API 按地址查询以太坊内部交易(Internal Transactions):

    语句:

    http://api.etherscan.io/api?module=account&action=txlistinternal&address={填入查询地址}&startblock=0&endblock=2702578&sort=asc&apikey={填入你的ApiKey}

    当然,不使用 apikey 也是可以查询的:

    http://api.etherscan.io/api?module=account&action=txlistinternal&address={填入查询地址}&startblock=0&endblock=2702578&sort=asc

    如果需要获取分页结果,设置一下pageoffset即可:

    https://api.etherscan.io/api?module=account&action=txlistinternal&address={填入查询地址}&startblock=0&endblock=2702578&page={页码}&offset={每页结果数}&sort=asc&apikey={填入你的ApiKey}

    Node.js 代码示例:

    const fetch = require('node-fetch');
    
    fetch('http://api.etherscan.io/api?module=account&action=txlistinternal&address={填入查询地址}&startblock=0&endblock=2702578&sort=asc&apikey={填入你的ApiKey}', {
        method: 'get',
    }).then(response => response.json()
        .then(data => console.log(data)));
    

    返回的 JSON 示例:

    {
      "status": "1",
      "message": "OK",
      "result": [
        {
          "blockNumber": "2535368",
          "timeStamp": "1477837690",
          "hash": "0x8a1a9989bda84f80143181a68bc137ecefa64d0d4ebde45dd94fc0cf49e70cb6",
          "from": "0x20d42f2e99a421147acf198d775395cac2e8b03d",
          "to": "",
          "value": "0",
          "contractAddress": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
          "input": "",
          "type": "create",
          "gas": "254791",
          "gasUsed": "46750",
          "traceId": "0",
          "isError": "0",
          "errCode": ""
        },
        {
          "blockNumber": "2535479",
          "timeStamp": "1477839134",
          "hash": "0x1a50f1dc0bc912745f7d09b988669f71d199719e2fb7592c2074ede9578032d0",
          "from": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
          "to": "0x20d42f2e99a421147acf198d775395cac2e8b03d",
          "value": "100000000000000000",
          "contractAddress": "",
          "input": "",
          "type": "call",
          "gas": "235231",
          "gasUsed": "0",
          "traceId": "0",
          "isError": "0",
          "errCode": ""
        },
        {
          "blockNumber": "2547590",
          "timeStamp": "1478012596",
          "hash": "0xee535e4016e766d9210d0bc47afeff48f12cd05f0b0b00aa0ed7019b4417f505",
          "from": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
          "to": "0x20d42f2e99a421147acf198d775395cac2e8b03d",
          "value": "1000000000000000000",
          "contractAddress": "",
          "input": "",
          "type": "call",
          "gas": "174995",
          "gasUsed": "0",
          "traceId": "0",
          "isError": "0",
          "errCode": ""
        }
      ]
    }
    

    Etherscan API 官方文档:https://etherscan.io/apis

    Etherscan API 思维导图:

    Etherscan API.png

    我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我:

    区块链社群 知识星球

    相关文章

      网友评论

        本文标题:Etherscan API 按地址查询内部交易 - 区块链数据开

        本文链接:https://www.haomeiwen.com/subject/ilxnvqtx.html