名称: 查找区块信息 描述: 从BSV区块链检索详细的区块信息。 允许的工具: “Bash(bun:*)”
查找区块信息
检索BSV区块链的详细区块信息。
API
使用WhatsOnChain获取完整区块数据(大小、交易数、难度、前一个区块哈希)。JungleBus /v1/block_header/get/{hash} 仅提供头字段 - 如果只需要哈希、高度、时间、默克尔根,直接使用该API。
何时使用
- 通过高度获取区块数据
- 通过哈希获取区块数据
- 查看区块统计(大小、交易数等)
用法
# 通过高度查找
bun run skills/lookup-block-info/scripts/lookup.ts --height 800000
# 通过哈希查找
bun run skills/lookup-block-info/scripts/lookup.ts --hash 00000000000000000320e...
# JSON输出
bun run skills/lookup-block-info/scripts/lookup.ts --height 800000 --json
# 显示帮助
bun run skills/lookup-block-info/scripts/lookup.ts --help
输出
默认格式
Block #1
Hash: 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048
Time: 2009-01-09 02:54:25 UTC
Size: 215 bytes
Transactions: 1
Merkle Root: 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
Previous: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
Difficulty: 1
JSON格式 (–json)
{
"height": 1,
"hash": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
"time": 1231469665,
"size": 215,
"txCount": 1,
"merkleRoot": "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
"previousHash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"difficulty": 1
}
错误处理
- 无效高度(负值): “错误: 高度必须为非负整数”, 退出 1
- 无效哈希格式: “错误: 哈希必须为64个十六进制字符”, 退出 1
- 区块未找到: “错误: 区块未找到”, 退出 1
- 网络/API错误: “错误: API请求失败: <原因>”, 退出 1
状态
完成 - 所有测试通过