eth_getBlockByHash - Base
Example code for the eth_getBlockByHash JSON-RPC method. Complete guide on how to use eth_getBlockByHash JSON-RPC in GetBlock Web3 documentation.
Parameters
Parameter
Type
Required
Description
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": ["0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2", true],
"id": "getblock.io"
}'const axios = require('axios');
const blockHash = '0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2';
const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_getBlockByHash',
params: [blockHash, true],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
const block = response.data.result;
console.log('Block Number:', parseInt(block.number, 16));
console.log('Transactions:', block.transactions.length);Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": {
"number": "0x12d687f",
"hash": "0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2",
"parentHash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"timestamp": "0x64a1b2c3",
"transactions": [],
"gasUsed": "0x5208",
"gasLimit": "0x1c9c380",
"baseFeePerGas": "0x5f5e100",
"miner": "0x4200000000000000000000000000000000000011"
}
}Response Parameters
Parameter
Type
Description
Use Cases
Error Handling
Error Code
Message
Description
Web3 Integration
Last updated
Was this helpful?