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.

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

Parameter
Type
Required
Description

blockHash

string

Yes

32-byte hash of the block

fullTransactions

boolean

Yes

If true, returns full transaction objects; if false, returns only transaction hashes

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"
}'

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

number

string

Block number in hex

hash

string

32-byte block hash

parentHash

string

32-byte parent block hash

timestamp

string

Unix timestamp of block creation

transactions

array

Array of transaction hashes or objects

gasUsed

string

Total gas used by all transactions

gasLimit

string

Maximum gas allowed in block

baseFeePerGas

string

EIP-1559 base fee per gas

miner

string

Address 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 Code
Message
Description

-32602

Invalid params

Invalid block hash format

-32603

Internal error

Block not found or node failure

-32600

Invalid request

Malformed JSON-RPC request

Web3 Integration

Last updated

Was this helpful?