监控ERC20合约代币充值

假设 充值账号0x617315ed9433de7b902ee33766888888888

假设 合约地址

https://etherscan.io/address/0x87026f792d09960232ca406e80c88888888

轮询的代币合约交易检测接口:

https://api.etherscan.io/api?module=account&action=txlist&address=0x87026f792d09960232ca406e80c88888888&startblock=6169598&endblock=99999999

第一个粗体表示代币合约地址,改成你自己的。第二个粗体代表区块起始位置,每次访问,都记录好最大值,下次从记录的最大值加1开始检测。

主链的api域名是api.etherscan.io,测试链是api-rinkeby.etherscan.io 。

 

接口获得的结果如下: 

{

  "status": "1",

  "message": "OK",

  "result": [{

    "blockNumber": "6173801",

    "timeStamp": "1534657648",

    "hash": "0x09a4b0a1c2e53717b4e22fa0a5b69704508888888883f1a62c",

    "nonce": "2352",

    "blockHash": "0x076e0fc9f52a2b431b561b75807082440288888881b54abec25d",

    "transactionIndex": "42",

    "from": "0xfe5854255eb1eb921588888888847ed2412a1d7",

    "to": "0x87026f792d09960232ca406e80c88888888",

    "value": "0",

    "gas": "120000",

    "gasPrice": "4000000000",

    "isError": "0",

    "txreceipt_status": "1",

    "input": "0xa9058888000000000000000000000000492eea2038aadc70125988888888885c2f9a80000000000000000000000000000000000000000000014dd8cd979f267b0f0000",

    "contractAddress": "",

    "cumulativeGasUsed": "2993975",

    "gasUsed": "37261",

    "confirmations": "5470"

  }, {

    "blockNumber": "6177544",

    "timeStamp": "1534711512",

    "hash":     "0xb9d8352ffe6c749afe531aee8ff3656de1c55908888888885294005cacf4",

    "nonce": "6",

    "blockHash": "0xc2044ed8d1fdff920526067e5f16d4d11f153388888855f7ba650b",

    "transactionIndex": "56",

    "from": "0xd9ca7d0a4ee0f4ef029d68888888888c06666",

    "to": "0x87026f792d09960232ca406e80c88888888",

    "value": "0",

    "gas": "120000",

    "gasPrice": "3000000000",

    "isError": "0",

    "txreceipt_status": "1",

    "input": "0xa9058888000000000000000000000000fe5854255eb1eb92188888886a3947ed2412a1d700000000000000000000000000000000000000000000083a100e6be0d5c80000",

    "contractAddress": "",

    "cumulativeGasUsed": "3784901",

    "gasUsed": "22197",

    "confirmations": "1727"

}, {

    "blockNumber": "6179161",

    "timeStamp": "1534735371",

    "hash": "0x01440032d9409b73a9b4c3eea3f04f6278b31fec5e6c938d2aa897e93cc01737",

    "nonce": "0",

    "blockHash": "0x858c03f858f0b047c7f743f3fcad2f4e3fb08d8a35a3c7ab274f02d947a55b48",

    "transactionIndex": "64",

    "from": "0xa0a8d65848575dcdcda3b4ae888888213e03f0d",

    "to": "0x87026f792d09960232ca406e80c88888888",

    "value": "0",

    "gas": "60000",

    "gasPrice": "1000000000",

    "isError": "0",

    "txreceipt_status": "1",

    "input": "0xa90588880000000000000000000000000617315ed9433de7b902ee3376688888888800000000000000000000000000000000000000000000000ad78ebc5ac6200000",

    "contractAddress": "",

    "cumulativeGasUsed": "5404133",

    "gasUsed": "37133",

    "confirmations": "110"

  }]

blockNumber代表交易所在的区块号码。

From是交易发起的用户账号;

To是代币的合约;

Input是交易的参数。

其中交易的参数如下:

0xa90588880000000000000000000000000617315ed9433de7b902ee3376688888888800000000000000000000000000000000000000000000000ad78ebc5ac6200000

 可以做以下分解:

Function: transfer(address _to, uint256 _value)

MethodID: 0xa9058888

[0]:  0000000000000000000000000617315ed9433de7b902ee33766888888888

[1]:  00000000000000000000000000000000000000000000000ad78ebc5ac6200000

上面的参数表示调用了0xa9058888(每个合约的transfer对应的method是唯一的,你需要检查一下你自己的method Id)这个方法,也就是转账方法。转账对象是账号0x617315ed9433de7b902ee33766888888888,转账金额是0xad78ebc5ac6200000,换成十进制就是200代币(去掉了18位小数的0)。 

你可能感兴趣的:(go语言,区块链,智能和玉)