以太坊JSON RPC手册

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

eth_getBlockByHash

返回具有指定哈希的块。

参数

  • DATA, 32字节 - 块哈希
  • Boolean - 为true时返回完整的交易对象,否则仅返回交易哈希
params: [
   '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
   true
]

返回值

Object - 匹配的块对象,如果未找到块则返回null,结构如下:

  • number: QUANTITY - 块编号,挂起块为null
  • hash: DATA, 32 Bytes - 块哈希,挂起块为null
  • parentHash: DATA, 32 Bytes - 父块的哈希
  • nonce: DATA, 8 Bytes - 生成的pow哈希,挂起块为null
  • sha3Uncles: DATA, 32 Bytes - 块中叔伯数据的SHA3哈希
  • logsBloom: DATA, 256 Bytes - 快日志的bloom过滤器,挂起块为null
  • transactionsRoot: DATA, 32 Bytes - 块中的交易树根节点
  • stateRoot: DATA, 32 Bytes - 块最终状态树的根节点
  • receiptsRoot: DATA, 32 Bytes - 块交易收据树的根节点
  • miner: DATA, 20 Bytes - 挖矿奖励的接收账户
  • difficulty: QUANTITY - 块难度,整数
  • totalDifficulty: QUANTITY - 截止到本块的链上总难度
  • extraData: DATA - 块额外数据
  • size: QUANTITY - 本块字节数
  • gasLimit: QUANTITY - 本块允许的最大gas用量
  • gasUsed: QUANTITY - 本块中所有交易使用的总gas用量
  • timestamp: QUANTITY - 块时间戳
  • transactions: Array - 交易对象数组,或32字节长的交易哈希数组
  • uncles: Array - 叔伯哈希数组

示例代码

请求:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", true],"id":1}'

响应:

{
"id":1,
"jsonrpc":"2.0",
"result": {
    "number": "0x1b4", // 436
    "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
    "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
    "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a",
    "difficulty": "0x027f07", // 163591
    "totalDifficulty":  "0x027f07", // 163591
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "size":  "0x027f07", // 163591
    "gasLimit": "0x9f759", // 653145
    "gasUsed": "0x9f759", // 653145
    "timestamp": "0x54e34e8e" // 1424182926
    "transactions": [{...},{ ... }] 
    "uncles": ["0x1606e5...", "0xd5145a9..."]
  }
}