Parameters
Maximum number of blocks to return
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": "getBlocksWithLimit",
"params": [
100000000,
10
]
}'
Request with Commitment
curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocksWithLimit",
"params": [
100000000,
10,
{
"commitment": "finalized"
}
]
}'
Using web3.js
import { Connection } from '@solana/web3.js';
const connection = new Connection('https://rpc.orbitflare.com');
// Get 10 blocks starting from slot
const blocks = await connection.getBlocksWithLimit(100000000, 10);
console.log('Blocks:', blocks);
// Get finalized blocks
const finalizedBlocks = await connection.getBlocksWithLimit(100000000, 10, 'finalized');
console.log('Finalized blocks:', finalizedBlocks);
Notes
- Returns confirmed blocks starting from the specified slot
- Results are returned in ascending order
- The limit controls the maximum number of blocks to return
- 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 limit reasonable to avoid timeouts
- Use this method for pagination instead of
getBlocks
- Cache results when appropriate to reduce RPC load
- Handle skipped slots in your application logic
Common Errors
Code | Message | Solution |
---|
-32602 | Invalid param: limit must be positive | Ensure limit is greater than 0 |
-32602 | Invalid param: limit too large | Reduce the limit size |
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32007 | Block information unavailable | Node may be bootstrapping or slot is too old |
Use Cases
-
Block Pagination
async function getBlocksPaginated(startSlot: number, pageSize: number) {
const blocks = await connection.getBlocksWithLimit(startSlot, pageSize);
const lastBlock = blocks[blocks.length - 1];
return {
blocks,
nextStartSlot: lastBlock ? lastBlock + 1 : null
};
}
-
Recent Block History
async function getRecentBlocks(count: number) {
const currentSlot = await connection.getSlot();
const blocks = await connection.getBlocksWithLimit(currentSlot - count, count);
return blocks.map(slot => ({
slot,
timestamp: new Date() // Add actual timestamp if available
}));
}
-
Block Streaming
async function* streamBlocks(startSlot: number, batchSize: number) {
let currentSlot = startSlot;
while (true) {
const blocks = await connection.getBlocksWithLimit(currentSlot, batchSize);
if (blocks.length === 0) {
break;
}
yield blocks;
currentSlot = blocks[blocks.length - 1] + 1;
}
}