web3.eth.getBlock

返回指定编号或哈希的块。

调用方法:

web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])

参数:

  • blockHashOrBlockNumber:String|Number,块号或哈希值,或者为以下字符串常量:”earliest”、”latest” 或”pending”。
  • returnTransactionObjects:Boolean,可选,默认值为false,如果设置为true,返回的快中将包含所有的交易对象, 否则仅返回交易哈希。
  • callback:Function,可选,当使用回调函数时将采用异步HTTP请求来访问节点。

返回值:

Object – 块对象:

  • number: Number – 块编号,当块处于pending状态时,值为null
  • hash: String, 32字节,块哈希,当块处于pending状态时,值为null
  • parentHash: String, 32字节,父块的哈希
  • nonce: String, 8字节,生成的POW哈希,块处于pending状态时,值为null
  • sha3Uncles: String, 32字节, 块中叔伯数据的SHA3值
  • logsBloom: String, 256字节,块中日志的bloom filter,当块处于pending状态时,值为null
  • transactionsRoot: String, 32字节,块交易树的根节点
  • stateRoot: String, 32字节,块最终状态树的根节点
  • miner: String, 20字节,接收挖矿奖励的矿工地址
  • difficulty: BigNumber , 块难度
  • totalDifficulty: BigNumber , 截止到本块的全链总难度
  • extraData: String ,块中的额外数据
  • size: Number,按字节计算的块大小
  • gasLimit: Number,本块允许的最大gas消耗量
  • gasUsed: Number ,块中所有交易使用的gas总量
  • timestamp: Number,块校验unix时间戳
  • transactions: Array,交易对象数组,或者是32字节的交易哈希值,取决于参数returnTransactionObjects的值
  • uncles: Array,叔伯块的哈希数组

示例代码:

var info = web3.eth.getBlock(3150);
console.log(info);
/*
{
  "number": 3,
  "hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
  "parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88",
  "nonce": "0xfb6e1a62d119228b",
  "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "transactionsRoot": "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee",
  "stateRoot": "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb",
  "miner": "0x8888f1f195afa192cfee860698584c030f4c9db1",
  "difficulty": BigNumber,
  "totalDifficulty": BigNumber,
  "size": 616,
  "extraData": "0x",
  "gasLimit": 3141592,
  "gasUsed": 21662,
  "timestamp": 1429287689,
  "transactions": [
    "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b"
  ],
  "uncles": []
}
*/

 

发表评论

后才能评论