getBlocks - Solana

This method returns the confirmed block slots in an inclusive slot range. The range is capped at 500,000 slots per request.

Parameters

ParameterTypeRequiredDescription
startSlotnumberYesFirst slot of the range, inclusive
endSlotnumberNoLast slot of the range, inclusive. Must be no more than 500,000 slots after startSlot
configobjectNoConfiguration object controlling commitment

Config Object

FieldTypeRequiredDescription
commitmentstringNoCommitment level: confirmed or finalized. The processed level is not supported

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getBlocks",
    "params": [397234556, 397234561],
    "id": "getblock.io"
}'

example.js

javascriptconst { Connection } = require('@solana/web3.js');

const connection = new Connection('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', 'confirmed');

const blocks = await connection.getBlocks(397234556, 397234561);

console.log(blocks);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getBlocks',
        'params': [397234556, 397234561],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getBlocks",
            "params": [397234556, 397234561],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": [
        397234556,
        397234557,
        397234558,
        397234560,
        397234561
    ]
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultarrayArray of confirmed block slots in the requested range

Use Cases

  • Gap Detection: Compare the returned slots against the range to find skipped slots
  • Indexer Scheduling: Enumerate slots to fetch before calling getBlock on each
  • Backfill Jobs: Chunk historical ranges into 500,000-slot windows
  • Liveness Checks: Measure how many slots in a window produced blocks

Error Handling

Error CodeMessageDescription
-32007Slot was skipped, or missing due to ledger jump to recent snapshotThe slot was skipped by the leader or predates the node's snapshot
-32009Slot was skipped, or missing in long-term storageThe slot is absent from the node's long-term ledger storage
-32602Invalid paramsRange exceeds 500,000 slots or endSlot precedes startSlot
-32603Internal errorNode failed to read the blockstore for the range