web3.eth.getBlock
优质
小牛编辑
125浏览
2023-12-01
web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])
返回块号或区块哈希值所对应的区块
参数:
Number|String
-(可选)如果未传递参数,默认使用web3.eth.defaultBlock
定义的块,否则使用指定区块。Boolean
-(可选)默认值为false
。true
会将区块包含的所有交易作为对象返回。否则只返回交易的哈希。Function
- 回调函数,用于支持异步的方式执行[async]。
返回值 - 区块对象:
Number
- 区块号。当这个区块处于pending
将会返回null
。hash
- 字符串,区块的哈希串。当这个区块处于pending
将会返回null
。parentHash
- 字符串,32字节的父区块的哈希值。nonce
- 字符串,8字节。POW生成的哈希。当这个区块处于pending
将会返回null
。sha3Uncles
- 字符串,32字节。叔区块的哈希值。logsBloom
- 字符串,区块日志的布隆过滤器9。当这个区块处于pending
将会返回null
。transactionsRoot
- 字符串,32字节,区块的交易前缀树的根。stateRoot
- 字符串,32字节。区块的最终状态前缀树的根。miner
- 字符串,20字节。这个区块获得奖励的矿工。difficulty
-BigNumber
类型。当前块的难度,整数。totalDifficulty
-BigNumber
类型。区块链到当前块的总难度,整数。extraData
- 字符串。当前块的extra data
字段。size
-Number
。当前这个块的字节大小。- gasLimit -
Number
,当前区块允许使用的最大gas
。 gasUsed
- 当前区块累计使用的总的gas
。timestamp
-Number
。区块打包时的unix
时间戳。transactions
- 数组。交易对象。或者是32字节的交易哈希。uncles
- 数组。叔哈希的数组。
示例:
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": []
}
*/