简介:Etherscan 大多数朋友都比较熟悉了,它是主流以太坊区块浏览器。Etherscan 有面向开发者提供 API 服务以方便其检索以太坊区块链信息。本文示例如何使用 Etherscan API 查询以太坊地址余额。
Etherscan 大多数朋友都比较熟悉了,它是主流以太坊区块浏览器。Etherscan 有面向开发者提供 API 服务以方便其检索以太坊区块链信息。
Etherscan API 在没有密钥的情况下,支持每秒最多五次请求。有更多请求需求可以在这里申请密钥:https://etherscancom.freshdesk.com/support/solutions/articles/35000022163-i-need-an-api-key
使用 Etherscan API 查询以太坊地址余额:
语句:
https://api.etherscan.io/api?module=account&action=balance&address={填入查询地址}&tag=latest&apikey=YourApiKeyToken
当然,不使用 apikey
也是可以查询的:
https://api.etherscan.io/api?module=account&action=balance&address={填入查询地址}&tag=latest
Node.js 代码示例:
const fetch = require('node-fetch');
fetch('https://api.etherscan.io/api?module=account&action=balance&address={填入查询地址}&tag=latest&apikey=YourApiKeyToken', {
method: 'get',
}).then(response => response.json()
.then(data => console.log(data)));
返回的 JSON 示例:
{"status":"1","message":"OK","result":"40807178566070000000000"}
Etherscan API 还支持批量查询以太坊地址余额,需要将action
参数设置为balancemulti
,然后就可以逗号隔开地址进行批量查询了:
语句:
https://api.etherscan.io/api?module=account&action=balancemulti&address={查询地址1},{查询地址2},{查询地址3}&tag=latest&apikey=YourApiKeyToken
返回的 JSON 示例:
{
"status": "1",
"message": "OK",
"result": [
{
"account": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
"balance": "40807178566070000000000"
},
{
"account": "0x63a9975ba31b0b9626b34300f7f627147df1f526",
"balance": "332567136222827062478"
},
{
"account": "0x198ef1ec325a96cc354c7266a038be8b5c558f67",
"balance": "0"
}
]
}
Etherscan API 官方文档:https://etherscan.io/apis
Etherscan API 思维导图:
我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我: