getBlocksWithLimit
The getBlocksWithLimit method returns a list of confirmed blocks starting from a specified slot, limited to a maximum number of blocks. This method is particularly useful when you need a specific quantity of blocks for processing, regardless of how many slots were skipped in between.
This method differs from getBlocks in that instead of specifying an end slot, you specify how many blocks you want to retrieve. This is more convenient for applications that process blocks in batches or implement pagination, as you can consistently request the same number of blocks without calculating slot ranges or handling range limits.
The method is commonly used by blockchain indexers, data pipelines, and monitoring tools that need to process blocks in fixed-size batches. It's especially useful for progressive synchronization where your application catches up with the chain by repeatedly fetching the next N blocks, processing them, and then requesting the next batch.
Parameters
parameter | type | description |
|---|---|---|
startSlot | number | The start slot, inclusive (u64) |
limit | number | Maximum number of blocks to return (u64). Must be no more than 500,000 |
config | object | Optional configuration object |
config.commitment | string | Level of commitment: 'confirmed' or 'finalized' (default: 'finalized'). 'processed' is not supported |
Return Object
field | type | description |
|---|---|---|
result | array | Array of slot numbers (u64) representing confirmed blocks, up to the specified limit, sorted in ascending order |
Request Example
Response Example
Tip: This method returns exactly the number of blocks you request (or fewer if you reach the end of the chain). The returned array length may be less than the limit if there aren't enough blocks available. Use this for batch processing where you need consistent batch sizes.