简介:Etherscan 大多数朋友都比较熟悉了,它是主流以太坊区块浏览器。Etherscan 有面向开发者提供 API 服务以方便其检索以太坊区块链信息。本文示例如何使用 Etherscan API 按地址查询以太坊普通(Normal)交易。
Etherscan 大多数朋友都比较熟悉了,它是主流以太坊区块浏览器。Etherscan 有面向开发者提供 API 服务以方便其检索以太坊区块链信息。
Etherscan API 在没有密钥的情况下,支持每秒最多五次请求。有更多请求需求可以在这里申请密钥:https://etherscancom.freshdesk.com/support/solutions/articles/35000022163-i-need-an-api-key
使用 Etherscan API 按地址查询以太坊普通(Normal)交易:
语句:
http://api.etherscan.io/api?module=account&action=txlist&address={填入查询地址}&startblock=0&endblock=99999999&sort=asc&apikey={填入你的ApiKey}
当然,不使用 apikey
也是可以查询的:
http://api.etherscan.io/api?module=account&action=txlist&address={填入查询地址}&startblock=0&endblock=99999999&sort=asc
如果需要获取分页结果:
https://api.etherscan.io/api?module=account&action=txlist&address={填入查询地址}&startblock=0&endblock=99999999&page={页码}&offset={每页结果数}&sort=asc&apikey={填入你的ApiKey}
Node.js 代码示例:
const fetch = require('node-fetch');
fetch('http://api.etherscan.io/api?module=account&action=txlist&address={填入查询地址}&startblock=0&endblock=99999999&sort=asc&apikey={填入你的ApiKey}', {
method: 'get',
}).then(response => response.json()
.then(data => console.log(data)));
返回的 JSON 示例:
{
"status": "1",
"message": "OK",
"result": [
{
"blockNumber": "0",
"blockHash": "",
"timeStamp": "1438269973",
"hash": "GENESIS_ddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
"nonce": "",
"transactionIndex": "0",
"from": "GENESIS",
"to": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
"value": "10000000000000000000000",
"gas": "0",
"gasPrice": "0",
"input": "",
"contractAddress": "",
"cumulativeGasUsed": "0",
"txreceipt_status": "",
"gasUsed": "0",
"confirmations": "7443069",
"isError": "0"
},
{
"blockNumber": "47884",
"blockHash": "0xf2988b9870e092f2898662ccdbc06e0e320a08139e9c6be98d0ce372f8611f22",
"timeStamp": "1438947953",
"hash": "0xad1c27dd8d0329dbc400021d7477b34ac41e84365bd54b45a4019a15deb10c0d",
"nonce": "0",
"transactionIndex": "0",
"from": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
"to": "0x2910543af39aba0cd09dbb2d50200b3e800a63d2",
"value": "5000000000000000000",
"gas": "23000",
"gasPrice": "400000000000",
"input": "0x454e34354139455138",
"contractAddress": "",
"cumulativeGasUsed": "21612",
"txreceipt_status": "",
"gasUsed": "21612",
"confirmations": "7395185",
"isError": "0"
},
{
"blockNumber": "47894",
"blockHash": "0x2d0a9228f22fe85596d246040d4fd7dc6b1a55920bae02b68e731d55a890b315",
"timeStamp": "1438948043",
"hash": "0x7e1503d2001cab2f432b56a62a3ee874782c8e33cbd79a664d155a758c1784a2",
"nonce": "1",
"transactionIndex": "0",
"from": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
"to": "0x2910543af39aba0cd09dbb2d50200b3e800a63d2",
"value": "9001000000000000000000",
"gas": "23000",
"gasPrice": "400000000000",
"input": "0x454e34354139455138",
"contractAddress": "",
"cumulativeGasUsed": "21612",
"txreceipt_status": "",
"gasUsed": "21612",
"confirmations": "7395175",
"isError": "0"
}
]
}
Etherscan API 官方文档:https://etherscan.io/apis
Etherscan API 思维导图:
Etherscan API.png我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我:
区块链社群 知识星球
网友评论