account/tokentx - 获取指定地址的ERC20代币转账交易
使用account模块的tokentx方法获取指定地址发生的ERC20代币转账事件。 每次调用最多返回10000个交易。
API调用
GET|POST /api
查询参数:
- module:account
- action:token
- address:要查询的以太坊地址
- startblock:起始区块号
- endblock:结束区块号
- sort:排序方式,asc - 升序,desc - 降序
- apikey:etherscan API密钥
- page:结果页号,可选
- offset:结果页交易数量,可选
- contractaddress:哪个ERC20合约的转账交易,可选
API返回结果
返回一个JSON对象,主要字段如下:
- status:状态码,1为成功
- message:调用描述信息,OK为成功
- result:调用结果数组,每个成员描述一个交易,包含如下字段:
- blockNumber:区块编号
- timeStamp:区块时间戳
- hash:交易哈希
- nonce:nonce值
- blockHash:区块哈希值
- from:发起账号
- to:接收账号
- value:交易金额
- gas:gas用量
- gasPrice:gas价格
- isError:是否发生错误,0表示没有错误,1表示发生错误
- txreceipt_status:交易收据状态
- input:交易附加数据,16进制字符串编码
- contractAddress:合约地址
- cumulativeGasUsed:区块累计交易用量
- gasUsed:本交易的gas用量
- confirmations:交易确认数
示例代码
以curl为例的调用代码如下,也可以直接点击这里查看在浏览器中的调用:
~$ curl http://api.etherscan.io/api?module=account&action=tokentx&address=0x4e83362442b8d1bec281594cea3050c8eb01311c&startblock=0&endblock=999999999&sort=asc&apikey=YourApiKeyToken
返回结果:
{
"status": "1",
"message": "OK",
"result": [
{
"blockNumber": "2228258",
"timeStamp": "1473433992",
"hash": "0x5f2cd76fd3656686e356bc02cc91d8d0726a16936fd08e67ed30467053225a86",
"nonce": "10",
"blockHash": "0x466dbced0a98e1b0490f787b51570850c8347960a4e92bd89acf85299e4cb9dc",
"from": "0x4e83362442b8d1bec281594cea3050c8eb01311c",
"contractAddress": "0xecf8f87f810ecf450940c9f60066b4a7a501d6a7",
"to": "0xac75b73394c329376c214663d92156afa864a77f",
"value": "101000000000000000000",
"tokenName": "\u0001",
"tokenSymbol": "\u0001",
"tokenDecimal": "1",
"transactionIndex": "10",
"gas": "1000000",
"gasPrice": "20000000000",
"gasUsed": "93657",
"cumulativeGasUsed": "684715",
"input": "0x2ac9bf090000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000005a34a38fc00a00000000000000000000000000000000000000000000000000005386e53c7de1e0000",
"confirmations": "5452386"
},
...
]
tokentx方法也支持分页,例如:
~$ curl https://api.etherscan.io/api?module=account&action=tokentx&contractaddress=0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2&page=1&offset=100&sort=asc&apikey=YourApiKeyToken
使用contractaddress可以限定仅返回指定ERC20代币合约的交易,例如:
~$ curl https://api.etherscan.io/api?module=account&action=tokentx&contractaddress=0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2&address=0x4e83362442b8d1bec281594cea3050c8eb01311c&page=1&offset=100&sort=asc&apikey=YourApiKeyToken