> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getBlocks

> Returns a list of confirmed blocks between two slots

## Parameters

<ParamField query="startSlot" type="number" required>
  Start slot (inclusive)
</ParamField>

<ParamField query="endSlot" type="number" required>
  End slot (inclusive)
</ParamField>

<ParamField query="config" type="object" optional>
  Configuration object containing the following optional fields:

  <Expandable title="config fields">
    <ParamField query="commitment" type="string" optional>
      The level of commitment to use:

      * `processed`: Latest block (unconfirmed)
      * `confirmed`: Confirmed by supermajority
      * `finalized`: Finalized by supermajority
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="result" type="array">
  Array of block slots in ascending order
</ResponseField>

## Code Examples

### Basic Request

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlocks",
  "params": [
    100000000,
    100000100
  ]
}'
```

### Request with Commitment

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlocks",
  "params": [
    100000000,
    100000100,
    {
      "commitment": "finalized"
    }
  ]
}'
```

### Using web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// 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

| 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

1. **Block Range Analysis**
   ```typescript theme={null}
   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**
   ```typescript theme={null}
   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**
   ```typescript theme={null}
   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;
   }
   ```
