getBlocksWithLimit
Learn getBlocksWithLimit use cases, code examples, request parameters, response structure, and tips.
The getBlocksWithLimit
RPC method retrieves a list of confirmed block slot numbers, starting from a specified slot and returning up to a defined limit. It’s especially useful when you need a fixed number of confirmed blocks following a known slot, without fetching full block data.
✅ Common Use Cases
Fetch a Fixed Number of Blocks Retrieve a specific number of confirmed block slots beginning at a particular start slot.
Paginated Block Scanning Process the blockchain in manageable chunks—ideal for block explorers or analytics pipelines.
Recent Block Monitoring Quickly get the most recent confirmed blocks following a known anchor slot.
🛠 Request Parameters
getBlocksWithLimit
accepts the following arguments:
start_slot
(u64, required): The first slot to start the query (inclusive).limit
(u64, required): The maximum number of block slots to return. ⚠️ The conceptual slot range (start_slot
tostart_slot + limit - 1
) must not exceed 500,000 slots.commitment
(string, optional): Commitment level for block confirmation:finalized
(default)confirmed
processed
If provided, this must be wrapped in a configuration object as the last parameter.
📦 Response Structure
The result
field contains an array of confirmed block slot numbers, up to the requested limit.
Example:
[355104000, 355104001, 355104002, 355104003, 355104004]
If start_slot
is 355104000
and limit
is 5
, this array represents the confirmed blocks found in that range.
💡 Examples
1. Fetch 5 Confirmed Blocks from a Start Slot
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocksWithLimit",
"params": [355104000, 5]
}
Fetch 3 Confirmed Blocks with a Specific Commitment Level
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocksWithLimit",
"params": [355104000, 3, { "commitment": "confirmed" }]
}
Code Examples
const fetch = require('node-fetch');
async function getBlocksWithLimit(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getBlocksWithLimit',
"params": [
355104000,
5,
{ "commitment": "confirmed" }
]
}),
});
const data = await response.json();
// Print the exact full response
console.log('Full RPC Response:');
console.log(JSON.stringify(data, null, 2));
return data;
} catch (error) {
console.error('Error getting health:', error.message);
return null;
}
}
// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';
getBlocksWithLimit(RPC_URL);
Example Respose
{
"jsonrpc": "2.0",
"result": [
355104000,
355104001,
355104002,
355104003,
355104004
],
"id": 1
}
🧠 Developer Tips
Understand Range Constraints The conceptual range scanned is from
start_slot
tostart_slot + limit - 1
. This must be ≤ 500,000 slots, regardless of how many actual blocks are returned.Ledger Retention Limits RPC nodes (like CoinVera) may not retain block info for very old slots. If
start_slot
is too far in the past, the method might return fewer blocks than expected—or none at all.Block Confirmation Levels The blocks returned reflect those confirmed at the specified commitment level. Recently confirmed blocks may vary slightly across nodes and configurations.
Choosing the Right Method Use
getBlocksWithLimit
when you:Know where to start
Want a fixed number of results For scanning a known range, use
getBlocks
instead.
Last updated