Parameters

startSlot
number
required

Start slot (inclusive)

endSlot
number
required

End slot (inclusive)

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": "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

  1. Returns confirmed blocks between the specified slots
  2. Results are returned in ascending order
  3. The range is inclusive of both start and end slots
  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 slot range reasonable to avoid timeouts
  3. Consider using getBlocksWithLimit for pagination
  4. Cache results when appropriate to reduce RPC load
  5. Handle skipped slots in your application logic

Common Errors

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

Use Cases

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