eth_getBlockByNumber - AVAX

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

Returns information about a C-Chain block by block number. Pass "latest", "earliest", "pending", "safe", or "finalized" as a block tag, or a hex-encoded block number. On Avalanche, sub-second finality means "safe" and "finalized" track very close to "latest".

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>/ext/bc/C/rpc' \
--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 (hex)

result.baseFeePerGas

string

EIP-1559 base fee per gas (hex)

result.transactions

array

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

Use Cases

  • Block-by-block indexing of C-Chain transactions

  • Building Snowtrace-style explorers and analytics

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

Error Handling

Status Code
Error Message
Cause

404

Not found

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

429

Too Many Requests

Rate limit exceeded for your plan

SDK Integration

Last updated

Was this helpful?