简介: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,错误信息,供调试使用。如果没有错误,则此字段不出现。
注意:在表示金额时,为避免浮点数产生精度问题,所有的金额单位均为聪。
查询语句:
示例:
获取2015年12月15日的区块列表:
Node.js 查询示例:
const fetch = require('node-fetch');
fetch('https://chain.api.btc.com/v3/block/date/{ymd}', {
method: 'get',
}).then(response => response.json()
.then(data => console.log(data.data)));
返回数据格式讲解:
{
height: int 块高度
version: int 块版本
mrkl_root: string Merkle Root
curr_max_timestamp: int 块最大时间戳
timestamp: int 块时间戳
bits: int bits
nonce: int nonce
hash: string 块哈希
prev_block_hash: string 前向块哈希,如不存在,则为 null
next_block_hash: string 后向块哈希,如不存在,则为 null
size: int 块体积
pool_difficulty: int 矿池难度
difficulty: int 块难度
tx_count: int 块奖励
reward_block: int 块奖励
reward_fees: int 块手续费
created_at: int 该记录系统处理时间,无业务含义
confirmations: int 确认数
extras: {
relayed_by: string 块播报方
}
}
比特大陆公共 API 服务思维导图:

我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我:

网友评论