getBlocksWithLimit

Returns a list of confirmed blocks starting at the given slot, up to a maximum count. Unlike getBlocks which requires an end slot, this method lets you specify how many blocks you want. This is particularly useful for pagination, incremental indexing, and scenarios where you need a fixed number of blocks from a starting point.

Parameters

#TypeRequiredDescription
1u64YesStart slot (inclusive)
2u64YesMaximum number of blocks to return (limit up to 500,000)
3objectNoConfiguration object

Configuration object fields:

FieldTypeDescription
commitmentstringCommitment level: confirmed or finalized (default finalized)

Response

Returns an array:

FieldTypeDescription
resultarray[u64]Array of confirmed slot numbers

Code Examples

cURL

1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2  "jsonrpc": "2.0",
3  "id": 1,
4  "method": "getBlocksWithLimit",
5  "params": [
6    166974000, 10
7  ]
8}'

TypeScript

1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2  method: "POST",
3  headers: { "Content-Type": "application/json" },
4  body: JSON.stringify({
5    jsonrpc: "2.0",
6    id: 1,
7    method: "getBlocksWithLimit",
8    params: [
9      166974000, 10
10    ]
11  }),
12});
13const { result } = await response.json();
14console.log("Blocks:", result.length);

Python

1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4    "jsonrpc": "2.0",
5    "id": 1,
6    "method": "getBlocksWithLimit",
7    "params": [
8        166974000, 10
9    ]
10})
11result = response.json()["result"]
12print(f"Blocks: {len(result)}")

Rust

1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let client = Client::new();
7    let res = client.post("http://[IP_ADDRESS]:[PORT]")
8        .json(&json!({
9            "jsonrpc": "2.0",
10            "id": 1,
11            "method": "getBlocksWithLimit",
12            "params": [
13                166974000_u64, 10_u64
14            ]
15        }))
16        .send().await?
17        .text().await?;
18    println!("{}", res);
19    Ok(())
20}

Example Response

1{
2  "jsonrpc": "2.0",
3  "result": [166974000, 166974001, 166974002, 166974003, 166974005, 166974006, 166974007, 166974008, 166974009, 166974010],
4  "id": 1
5}