getBlocks
Learn getBlocks use cases, code examples, request parameters, response structure, and tips.
The getBlocks
RPC method returns a list of confirmed block slot numbers between a specified start_slot
and an optional end_slot
. It’s useful when you need to know which blocks were confirmed within a certain range—without fetching full block contents.
✅ Common Use Cases
Identify Confirmed Blocks in a Range Quickly fetch all block slots that were successfully confirmed between two slots.
Iterate Over Confirmed Slots Use the list of confirmed slots to loop through and fetch detailed block data later via
getBlock
.Audit Block Presence Verify whether blocks exist across a specific slot range for basic validation or reporting.
🛠 Request Parameters
getBlocks
accepts the following parameters:
start_slot
(u64, required): The first slot of the range (inclusive).end_slot
(u64, optional): The last slot of the range (inclusive). If omitted, the method will return confirmed blocks up to the latest available slot. ⚠️ The range betweenstart_slot
andend_slot
must not exceed 500,000 slots.commitment
(string, optional): Commitment level passed as a field in a config object. If omitted, the node's default is used. Typical values:processed
confirmed
finalized
📦 Response Structure
The result
field will be an array of slot numbers (as unsigned 64-bit integers), each representing a confirmed block.
[355104000, 355104001, 355104002, 355104003, 355104004]
This means blocks were confirmed at these slots—note that some slots may be skipped (e.g., 355104004).
💡 Examples
1. Get Confirmed Blocks in a Slot Range
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [355104000, 355104001]
}
Get Blocks from Start Slot to Latest Confirmed Slot
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [355104000]
}
Get Blocks Using a Specific Commitment Level
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [355104000, 355104001, { "commitment": "confirmed" }]
}
Code Examples
const fetch = require('node-fetch');
async function getBlocks(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getBlocks',
"params": [
355104000,
355104001,
{ "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';
getBlocks(RPC_URL);
Example Response
{
"jsonrpc": "2.0",
"result": [
355104000,
355104001
],
"id": 1
}
🧠 Developer Tips
Range Limit Enforcement The maximum allowed range is 500,000 slots. Splitting larger ranges into chunks is required for historical scans.
Ledger Retention Differences Very old slot data may not be available on all RPC nodes. Empty arrays or errors might be returned for out-of-retention queries.
Consistency with Commitment Block confirmation status can vary depending on the
commitment
level and the specific RPC node queried—especially for recent slots.Use as a Prefilter for
getBlock
getBlocks
is often used to determine which blocks exist before making multiple calls togetBlock
for deeper inspection.Effective Pagination Strategy For scanning long history segments, implement pagination by dividing your range into multiple sub-ranges of 500,000 slots or fewer.
Last updated