For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_getBlockByNumber - Ethereum

Example code for the eth_getBlockByNumber JSON RPC method. Сomplete guide on how to use eth_getBlockByNumber JSON RPC in GetBlock Web3 documentation.

This method returns block data given a block number or tag. The block reference can be a hex-encoded number or one of the tags latest, earliest, pending, finalized (post-Merge finalized block), or safe (justified block). This is the most common block-lookup method — used by every block explorer, indexer, and chain-observation tool.

Parameters

Parameter
Type
Required
Description

blockParameter

string

Yes

Block number in hex, or latest, earliest, pending, finalized, safe

fullTransactionObjects

boolean

Yes

If true, returns full transaction objects; if false, returns just 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_getBlockByNumber",
    "params": [
        "latest",
        false
    ],
    "id": "getblock.io"
}'
example.js
const axios = require('axios');

const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_getBlockByNumber',
    params: [
        "latest",
        false
    ],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

Response

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result.number

string

Hex-encoded block number

result.hash

string

32-byte block hash

result.parentHash

string

Hash of the parent block

result.nonce

string

8-byte block nonce (deprecated post-Merge, always 0x0000000000000000)

result.sha3Uncles

string

keccak256 of the uncles list (empty post-Merge)

result.logsBloom

string

256-byte bloom filter over the block's logs

result.transactionsRoot

string

Root of the transactions trie

result.stateRoot

string

Root of the state trie after processing the block

result.receiptsRoot

string

Root of the receipts trie

result.miner

string

Address that received the block-level fee (fee recipient / proposer)

result.difficulty

string

Block difficulty (0x0 post-Merge)

result.totalDifficulty

string

Cumulative chain difficulty at this block

result.extraData

string

Arbitrary extra data (up to 32 bytes)

result.size

string

Size of the block in bytes (hex)

result.gasLimit

string

Maximum gas allowed in the block (hex)

result.gasUsed

string

Actual gas consumed by transactions in the block

result.timestamp

string

Unix timestamp of block production (hex)

result.baseFeePerGas

string

EIP-1559 base fee per gas (wei, hex)

result.blobGasUsed

string

Total blob gas consumed by blob transactions in the block (post-Cancun)

result.excessBlobGas

string

Excess blob gas carried into next block (post-Cancun)

result.withdrawalsRoot

string

Root of the block's withdrawals list (post-Shapella)

result.parentBeaconBlockRoot

string

Beacon block root of the parent (post-Cancun / EIP-4788)

result.requestsHash

string

Hash of the block's execution-layer requests list (post-Pectra / EIP-7685)

result.mixHash

string

Prev-randao value (post-Merge, formerly PoW mix digest)

result.uncles

array of string

Uncle block hashes (empty post-Merge)

result.transactions

array

Transaction hashes, or full transaction objects if fullTransactionObjects=true

result.withdrawals

array of object

Consensus-layer withdrawals credited in the block (post-Shapella)

Use Cases

  • Latest Block Polling: Poll latest to detect chain progress and drive per-block indexing workflows

  • Finality-Aware Reads: Use finalized to read from the beacon-chain-finalized tip, immune to reorgs

  • Historical Backfill: Iterate through historical block numbers to backfill an indexer or analytics database

  • Transaction Enumeration: Pass fullTransactionObjects=true to fetch every transaction in a block in a single call

Error Handling

Error Code
Message
Description

-32602

Invalid params

Block parameter is malformed or a numeric value is beyond the chain tip

-32603

Internal error

Node failed to retrieve the block

Web3 Integration

Was this helpful?