get_block_headers_range - Monero

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

This method returns block headers for all blocks in a given range, inclusive at both ends. Use it to efficiently fetch headers in bulk for indexing.

Parameters

Parameter
Type
Required
Description

start_height

unsigned int

Yes

First block height in the range (inclusive)

end_height

unsigned int

Yes

Last block height in the range (inclusive)

Request Example

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "get_block_headers_range",
    "params": {
        "start_height": 1545999,
        "end_height": 1546000
    },
    "id": "getblock.io"
}'

Response Example

Response Parameters

Field
Type
Description

result.headers

array

Array of block headers in the requested range

result.headers[].height

unsigned int

Height of this block

result.headers[].hash

string

Block hash

result.headers[].timestamp

unsigned int

Unix timestamp

result.headers[].reward

unsigned int

Coinbase reward in atomic units

Use Cases

  • Bulk-indexing block metadata efficiently

  • Backfilling block analytics dashboards

  • Computing rolling block-time statistics

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

-2

Invalid range

end_height is less than start_height or exceeds chain tip

SDK Integration

Last updated

Was this helpful?