The eth_getBlockByHash
method returns comprehensive information about a specific block identified by its unique 32-byte hash. This powerful method provides access to all block properties including transactions, gas metrics, miner information, timestamps, and more, making it essential for blockchain explorers and data analysis.
This method retrieves detailed data about a specific block using its hash as the identifier, with options to include either complete transaction details or just transaction hashes.
The hash (32 bytes) of the block
If true, returns full transaction objects; if false, returns only transaction hashes
A block object, or null if no block was found
Base fee per gas in hexadecimal (post EIP-1559)
The difficulty for this block in hexadecimal
Extra data field of this block
Maximum gas allowed in this block in hexadecimal
Total gas used by all transactions in hexadecimal
Hash of the block, null if pending
Bloom filter for the logs, null if pending
Address of the miner/validator
256-bit hash in hexadecimal
Hash of the proof-of-work, null if pending
Block number in hexadecimal, null if pending
Hash of the parent block
Root of the receipts trie
SHA3 of the uncles data
Size of this block in bytes (hexadecimal)
Root of the final state trie
Unix timestamp when the block was collated
Total difficulty of the chain until this block
Array of transaction objects or hashes
Root of the transaction trie
Array of uncle hashes
Array of validator withdrawals (post EIP-4895)
Merkle root of withdrawals (post EIP-4895)
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"baseFeePerGas": "0x41a2b3591",
"difficulty": "0x0",
"extraData": "0x556e697377617020426c6f636b20231242353045",
"gasLimit": "0x1c9c380",
"gasUsed": "0x189b1f1",
"hash": "0x4f32106f6ac5b44248aeda10c3e718f1048ddc274629cd1897a0ff1f7926c41e",
"logsBloom": "0xe54b0921498ad482b83...[truncated]",
"miner": "0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990",
"mixHash": "0x51c1b337d7ec2023e7bfd47907a1ee256668e46fb9feb0007c62f9bc2a8a19a7",
"nonce": "0x0000000000000000",
"number": "0x112a880",
"parentHash": "0xeea8dce30e2d7c2a7ffe35b6fc2c60782f59a123ff2812e85bf4a49839c6d5a2",
"receiptsRoot": "0x14a87619e588c1ef9f8c69fd8e3dff2a49b2c73f19871a74a7e1d97d67d00416",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x1284d",
"stateRoot": "0xb87823a3aea0dd94ffe84481962c8f988e3c2ffac98a9af2b81c1c3e4fcc6dc0",
"timestamp": "0x65f0d46e",
"totalDifficulty": "0xc70d815d562d3cfa955",
"transactions": [
"0x5a8b22ab3e70ee6ee4b15b48b1c88d8c01806a677ab8938c68dc4323cf51ae7a",
"0x8d2fcaa1aef4f4f19aa35bf9d91b34e24902efcaf670953a0bf7e0a6dc585e53"
// ... additional transaction hashes
],
"transactionsRoot": "0x39f9c7a211b008becd35bfbceaf186d564fcb737a9c026f8af7b5d89a8989143",
"uncles": [],
"withdrawals": [
{
"index": "0x57ca86",
"validatorIndex": "0x17384",
"address": "0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f",
"amount": "0x12a05f200"
}
// ... additional withdrawals
],
"withdrawalsRoot": "0x36a75a6993b676f8196354ed14e3c77167b9ae823211706b30aa125c3a5dac28"
}
}
The second parameter determines how transaction data is returned:
false
: Only transaction hashes are returned (more efficient for block scanning)true
: Complete transaction objects are returned (useful when you need transaction details)// Example of retrieving and processing a significant block
const significantBlocks = {
'The Merge Block': '0x4f32106f6ac5b44248aeda10c3e718f1048ddc274629cd1897a0ff1f7926c41e',
'First EIP-1559 Block': '0x9b83c12c569ba25654ce34563540e58a0f8acee4645178544a2a35ccfbdba6cc',
};
async function getHistoricalBlock(label) {
const blockHash = significantBlocks[label];
const blockInfo = await provider.send('eth_getBlockByHash', [blockHash, false]);
// Analysis
const timestamp = new Date(parseInt(blockInfo.timestamp, 16) * 1000);
const gasUsedPercent = (parseInt(blockInfo.gasUsed, 16) / parseInt(blockInfo.gasLimit, 16)) * 100;
console.log(`${label} mined on ${timestamp.toUTCString()}`);
console.log(`Gas utilization: ${gasUsedPercent.toFixed(2)}%`);
console.log(`Transactions: ${blockInfo.transactions.length}`);
}