Returns the block corresponding to the block number or block hash
transfer:
web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])
parameter:
blockHashOrBlockNumber
: Number|String - (optional) If no parameter is passed, the block defined by web3.eth.defaultBlock is used by default, otherwise the specified block is used.returnTransactionObjects
: Boolean - (optional) Default is false. true will return all transactions contained in the block as objects. Otherwise just return the hash of the transaction.callback
: Function - callback function, used to support asynchronous execution 7.
Return value - block object:
- Number - the block number. Returns null when the block is pending.
- hash - string, the hash of the block. Returns null when the block is pending.
- parentHash - String, 32 bytes hash of parent block.
- nonce - String, 8 bytes. POW generated hash. Returns null when the block is pending.
- sha3Uncles - String, 32 bytes. The hash of the uncle block.
- logsBloom - String, Bloom filter 9 for block logs. Returns null when the block is pending.
- transactionsRoot - String, 32 bytes, the root of the block's transaction prefix tree.
- stateRoot - String, 32 bytes. The root of the final state prefix tree for the block.
- miner - String, 20 bytes. The miner who received the reward for this block.
- difficulty - BigNumber type. The difficulty of the current block, an integer.
- totalDifficulty - BigNumber type. The total difficulty of the blockchain to the current block, an integer.
- extraData - String. The extra data field of the current block.
- size - Number. The current size in bytes of this block.
- gasLimit - Number, the maximum gas allowed for the current block.
- gasUsed - The total gas cumulatively used by the current block.
- timestamp - Number. The unix timestamp when the block was packed.
- transactions - array. Trading partners. Or a 32-byte transaction hash.
- uncles - array. Array of uncle hashes.
Example:
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": []
}
*/
Amway two tutorials: