> For the complete documentation index, see [llms.txt](https://docs.coinvera.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coinvera.io/integration/solana/rpc/getblockswithlimit.md).

# getBlocksWithLimit

The `getBlocksWithLimit` RPC method retrieves a list of **confirmed block slot numbers**, starting from a specified slot and returning up to a defined limit. It’s especially useful when you need a fixed number of confirmed blocks following a known slot, without fetching full block data.

***

#### ✅ Common Use Cases

* **Fetch a Fixed Number of Blocks**\
  Retrieve a specific number of confirmed block slots beginning at a particular start slot.
* **Paginated Block Scanning**\
  Process the blockchain in manageable chunks—ideal for block explorers or analytics pipelines.
* **Recent Block Monitoring**\
  Quickly get the most recent confirmed blocks following a known anchor slot.

***

#### 🛠 Request Parameters

`getBlocksWithLimit` accepts the following arguments:

* **`start_slot`** (*u64, required*):\
  The first slot to start the query (inclusive).
* **`limit`** (*u64, required*):\
  The maximum number of block slots to return.\
  ⚠️ The conceptual slot range (`start_slot` to `start_slot + limit - 1`) must **not exceed 500,000 slots**.
* **`commitment`** (*string, optional*):\
  Commitment level for block confirmation:
  * `finalized` *(default)*
  * `confirmed`
  * `processed`\
    If provided, this must be wrapped in a configuration object as the last parameter.

***

#### 📦 Response Structure

The `result` field contains an array of **confirmed block slot numbers**, up to the requested limit.

**Example:**

```json
[355104000, 355104001, 355104002, 355104003, 355104004]
```

If `start_slot` is `355104000`and `limit` is `5`, this array represents the confirmed blocks found in that range.

#### 💡 Examples

**1. Fetch 5 Confirmed Blocks from a Start Slot**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlocksWithLimit",
  "params": [355104000, 5]
}

```

2. **Fetch 3 Confirmed Blocks with a Specific Commitment Level**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlocksWithLimit",
  "params": [355104000, 3, { "commitment": "confirmed" }]
}

```

**Code Examples**

{% tabs %}
{% tab title="Nodejs" %}

```javascript
const fetch = require('node-fetch');

async function getBlocksWithLimit(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getBlocksWithLimit',
        "params": [
            355104000,
            5,
            { "commitment": "confirmed" }
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

getBlocksWithLimit(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import json
import asyncio
import aiohttp

async def get_blocks_with_limit(rpc_url):
    try:
        payload = {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getBlocksWithLimit",
            "params": [
                355104000,
                5,
                {"commitment": "confirmed"}
            ]
        }
        
        async with aiohttp.ClientSession() as session:
            async with session.post(
                rpc_url,
                headers={'Content-Type': 'application/json'},
                json=payload
            ) as response:
                data = await response.json()
                
                # Print the exact full response
                print('Full RPC Response:')
                print(json.dumps(data, indent=2))
                
                return data
                
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
async def main():
    RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
    await get_blocks_with_limit(RPC_URL)

# Run the async function
if __name__ == "__main__":
    asyncio.run(main())
```

{% endtab %}
{% endtabs %}

**Example Respose**

```json
{
  "jsonrpc": "2.0",
  "result": [
    355104000,
    355104001,
    355104002,
    355104003,
    355104004
  ],
  "id": 1
}
```

#### 🧠 Developer Tips

* **Understand Range Constraints**\
  The **conceptual range scanned** is from `start_slot` to `start_slot + limit - 1`. This must be ≤ 500,000 slots, regardless of how many actual blocks are returned.
* **Ledger Retention Limits**\
  RPC nodes (like **CoinVera**) may not retain block info for very old slots. If `start_slot` is too far in the past, the method might return fewer blocks than expected—or none at all.
* **Block Confirmation Levels**\
  The blocks returned reflect those confirmed at the specified commitment level. Recently confirmed blocks may vary slightly across nodes and configurations.
* **Choosing the Right Method**\
  Use `getBlocksWithLimit` when you:
  * Know where to start
  * Want a **fixed number** of results\
    For scanning a known range, use `getBlocks` instead.
