简介:BTC.com 是比特大陆旗下区块浏览器,提供 BTC、BCH 和 ETH 的区块链信息浏览查询服务,其中 BTC 和 BCH 均提供公共 API。本文整理使用 API 获取比特币地址交易列表的实现。
BTC.com 是比特大陆旗下区块浏览器,提供 BTC、BCH 和 ETH 的区块链信息浏览查询服务,其中 BTC 和 BCH 均提供公共 API。使用公共 API 不需要密钥,目前 API 速率限制为 每分钟120次(有需要可联系提高)。
本文整理使用 API 获取比特币地址交易列表的实现。
BTC.com 比特币 BTC API 官方文档:https://btc.com/api-doc
API 统一响应格式:
{
"data": ..., //具体的 API 响应结果
"err_no": 0,
"err_msg": null
}
响应体中的 data、err_no 和 err_msg 为固定字段,含义如下:
data,具体 API 响应的数据
error_no,错误码,0为正常,非0为错误,具体的错误码对照如下:
0 正常
1 找不到该资源
2 参数错误
error_msg,错误信息,供调试使用。如果没有错误,则此字段不出现。
注意:在表示金额时,为避免浮点数产生精度问题,所有的金额单位均为聪。
查询语句:
https://chain.api.btc.com/v3/address/{address}/tx
参数:
page
,可选,默认为1,页码
pagesize
,可选,默认为50,可选范围为1-50,分页大小
示例:
https://chain.api.btc.com/v3/address/15urYnyeJe3gwbGJ74wcX89Tz7ZtsFDVew/tx
Node.js 查询示例:
const fetch = require('node-fetch');
fetch('https://chain.api.btc.com/v3/address/{address}/tx', {
method: 'get',
}).then(response => response.json()
.then(data => console.log(data)));
返回的 JSON 示例:
{ data:
{ total_count: 6263,
page: 1,
pagesize: 50,
list:
[ { confirmations: 26168,
block_height: 543405,
block_hash: '',
block_time: 1538112895,
created_at: 1538112044,
fee: 1671,
hash: '1dfa50ff5de09308834d333806c9a70dc663ace1164d68da3d7087fe6b59ebcb',
inputs_count: 5,
inputs_value: 102039774,
is_coinbase: false,
is_double_spend: false,
is_sw_tx: false,
weight: 3128,
vsize: 782,
witness_hash: '1dfa50ff5de09308834d333806c9a70dc663ace1164d68da3d7087fe6b59ebcb',
lock_time: 543404,
outputs_count: 1,
outputs_value: 102038103,
size: 782,
sigops: 4,
version: 2,
inputs: [ [Object], [Object], [Object], [Object], [Object] ],
outputs: [ [Object] ],
balance_diff: -100050000 },
{ confirmations: 84807,
block_height: 484766,
block_hash: '',
block_time: 1505186936,
created_at: 1520157321,
fee: 3340,
hash: '374471afc6d2978ee002cf101180b49e5ef066d822d877c4445644f3fc9f1f29',
inputs_count: 2,
inputs_value: 163589,
is_coinbase: false,
is_double_spend: false,
is_sw_tx: false,
weight: 1628,
vsize: 407,
witness_hash: '374471afc6d2978ee002cf101180b49e5ef066d822d877c4445644f3fc9f1f29',
lock_time: 0,
outputs_count: 3,
outputs_value: 160249,
size: 407,
sigops: 12,
version: 1,
inputs: [ [Object], [Object] ],
outputs: [ [Object], [Object], [Object] ],
balance_diff: 20000 } ] },
err_no: 0,
err_msg: null }
比特大陆公共 API 服务思维导图:
![](https://img.haomeiwen.com/i7031412/e1d114298d506b44.png)
我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我:
![](https://img.haomeiwen.com/i7031412/b92c912401e3b9d1.png)
网友评论