Parameters
Configuration object containing the following optional fields:
The level of commitment to use:
processed
: Latest block (unconfirmed)
confirmed
: Confirmed by supermajority
finalized
: Finalized by supermajority
Response
Array of block slots in ascending order
Code Examples
Basic Request
curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [
100000000,
100000100
]
}'
Request with Commitment
curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [
100000000,
100000100,
{
"commitment": "finalized"
}
]
}'
Using web3.js
import { Connection } from '@solana/web3.js';
const connection = new Connection('https://rpc.orbitflare.com');
// Get blocks in range
const blocks = await connection.getBlocks(100000000, 100000100);
console.log('Blocks:', blocks);
// Get finalized blocks
const finalizedBlocks = await connection.getBlocks(100000000, 100000100, 'finalized');
console.log('Finalized blocks:', finalizedBlocks);
Notes
- Returns confirmed blocks between the specified slots
- Results are returned in ascending order
- The range is inclusive of both start and end slots
- Some slots may be skipped (no block produced)
- The response is immediate as it reads from the current state
Best Practices
- Use appropriate commitment level based on your needs:
processed
for latest blocks
confirmed
for high probability finality
finalized
for guaranteed finality
- Keep the slot range reasonable to avoid timeouts
- Consider using
getBlocksWithLimit
for pagination
- Cache results when appropriate to reduce RPC load
- Handle skipped slots in your application logic
Common Errors
Code | Message | Solution |
---|
-32602 | Invalid param: startSlot must be less than endSlot | Ensure startSlot is less than endSlot |
-32602 | Invalid param: slot range too large | Reduce the slot range size |
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32007 | Block information unavailable | Node may be bootstrapping or range is too old |
Use Cases
-
Block Range Analysis
async function analyzeBlockRange(startSlot: number, endSlot: number) {
const blocks = await connection.getBlocks(startSlot, endSlot);
const totalSlots = endSlot - startSlot + 1;
const skippedSlots = totalSlots - blocks.length;
console.log(`Total slots: ${totalSlots}`);
console.log(`Blocks produced: ${blocks.length}`);
console.log(`Skipped slots: ${skippedSlots}`);
console.log(`Block production rate: ${(blocks.length / totalSlots) * 100}%`);
}
-
Block History Tracking
interface BlockHistory {
startSlot: number;
endSlot: number;
blocks: number[];
timestamp: Date;
}
async function trackBlockHistory(startSlot: number, endSlot: number) {
const blocks = await connection.getBlocks(startSlot, endSlot);
const history: BlockHistory = {
startSlot,
endSlot,
blocks,
timestamp: new Date()
};
storeBlockHistory(history);
return history;
}
-
Block Gap Detection
async function detectBlockGaps(startSlot: number, endSlot: number) {
const blocks = await connection.getBlocks(startSlot, endSlot);
const gaps = [];
for (let i = 0; i < blocks.length - 1; i++) {
const current = blocks[i];
const next = blocks[i + 1];
if (next - current > 1) {
gaps.push({
start: current + 1,
end: next - 1,
length: next - current - 1
});
}
}
return gaps;
}