Parameters

startSlot
number
required

Start slot (inclusive)

limit
number
required

Maximum number of blocks to return

config
object

Configuration object containing the following optional fields:

Response

result
array

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

  1. Returns confirmed blocks starting from the specified slot
  2. Results are returned in ascending order
  3. The limit controls the maximum number of blocks to return
  4. Some slots may be skipped (no block produced)
  5. The response is immediate as it reads from the current state

Best Practices

  1. Use appropriate commitment level based on your needs:
    • processed for latest blocks
    • confirmed for high probability finality
    • finalized for guaranteed finality
  2. Keep the limit reasonable to avoid timeouts
  3. Use this method for pagination instead of getBlocks
  4. Cache results when appropriate to reduce RPC load
  5. Handle skipped slots in your application logic

Common Errors

CodeMessageSolution
-32602Invalid param: limit must be positiveEnsure limit is greater than 0
-32602Invalid param: limit too largeReduce the limit size
-32601Method not foundVerify you’re connected to a Solana RPC node
-32007Block information unavailableNode may be bootstrapping or slot is too old

Use Cases

  1. 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
      };
    }
    
  2. 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
      }));
    }
    
  3. 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;
      }
    }