eth_getBlockByNumber - opBNB

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

This method returns information about a block by block number. Pass "latest", "earliest", "pending", "safe", or "finalized" as a block tag, or a hex-encoded block number. The second argument controls whether the response includes full transaction objects or only transaction hashes.

Parameters

Parameter
Type
Required
Description

blockParameter

string

Yes

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

fullTransactions

boolean

Yes

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

Request Example

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

Response Example

Response Parameters

Field
Type
Description

result.number

string

Block number (hex)

result.hash

string

Block hash (32 bytes hex)

result.parentHash

string

Hash of the parent block

result.timestamp

string

Unix timestamp at which the block was sealed (hex)

result.gasLimit

string

Maximum gas allowed in this block (hex)

result.gasUsed

string

Total gas used by all transactions in this block (hex)

result.transactions

array

Array of transaction hashes, or full transaction objects if fullTransactions=true

result.stateRoot

string

Root of the final state trie of the block

result.receiptsRoot

string

Root of the receipts trie of the block

Use Cases

  • Block-by-block indexing of opBNB transactions

  • Building explorers and analytics dashboards

  • Computing block-level statistics (gas usage, tx count, fees)

  • Verifying parent-chain relationships in light clients

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32601

Method not found

The method is not supported by this node

429

Too Many Requests

Rate limit exceeded for your plan

SDK Integration

Was this helpful?