> ## 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.

# getBlocksWithLimit

> Returns a list of confirmed blocks starting at the given slot

## Parameters

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

<ParamField query="limit" type="number" required>
  Maximum number of blocks to return
</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": "getBlocksWithLimit",
  "params": [
    100000000,
    10
  ]
}'
```

### 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": "getBlocksWithLimit",
  "params": [
    100000000,
    10,
    {
      "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 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

| 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

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