eth_getBlockByHash - Base

The eth_getBlockByHash method returns information about a block by its hash. This method is useful when you have a specific block hash and need to retrieve the complete block data.

Parameters

ParameterTypeRequiredDescription
blockHashstringYes32-byte hash of the block
fullTransactionsbooleanYesIf true, returns full transaction objects; if false, returns only transaction hashes

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getBlockByHash",
    "params": ["0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2", true],
    "id": "getblock.io"
}'
javascriptconst axios = require('axios');

const blockHash = '0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2';

const response = await axios.post('https://shared.eu-central-1.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);
pythonimport requests

block_hash = '0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2'

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_getBlockByHash',
        'params': [block_hash, True],
        'id': 'getblock.io'
    }
)

result = response.json()
block = result['result']
if block:
    print(f'Block Number: {int(block["number"], 16)}')
    print(f'Transactions: {len(block["transactions"])}')
rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let block_hash = "0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2";
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "eth_getBlockByHash",
            "params": [block_hash, true],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Block: {}", serde_json::to_string_pretty(&response["result"])?);
    Ok(())
}

Response

json{
    "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

ParameterTypeDescription
numberstringBlock number in hex
hashstring32-byte block hash
parentHashstring32-byte parent block hash
timestampstringUnix timestamp of block creation
transactionsarrayArray of transaction hashes or objects
gasUsedstringTotal gas used by all transactions
gasLimitstringMaximum gas allowed in block
baseFeePerGasstringEIP-1559 base fee per gas
minerstringAddress of the sequencer

Use Cases

  1. Block Verification: Verify block data using a known hash
  2. Transaction Lookup: Retrieve all transactions from a specific block
  3. Chain Analysis: Analyze block data for research purposes
  4. Event Processing: Process events from a specific block by hash
  5. Fork Detection: Compare blocks across different nodes

Error Handling

Error CodeMessageDescription
-32602Invalid paramsInvalid block hash format
-32603Internal errorBlock not found or node failure
-32600Invalid requestMalformed JSON-RPC request

Web3 Integration

javascriptconst { ethers } = require('ethers');

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

async function getBlockByHash(blockHash) {
    const block = await provider.getBlock(blockHash);
    
    if (block) {
        console.log('Block Number:', block.number);
        console.log('Hash:', block.hash);
        console.log('Timestamp:', new Date(block.timestamp * 1000));
        console.log('Transactions:', block.transactions.length);
    } else {
        console.log('Block not found');
    }
    
    return block;
}

getBlockByHash('0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2');
javascriptimport { createPublicClient, http } from 'viem';
import { base } from 'viem/chains';

const client = createPublicClient({
    chain: base,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

async function getBlockByHash(blockHash) {
    const block = await client.getBlock({
        blockHash: blockHash,
        includeTransactions: true
    });
    
    console.log('Block Number:', block.number);
    console.log('Hash:', block.hash);
    console.log('Transactions:', block.transactions.length);
    
    return block;
}

getBlockByHash('0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2');