getBlocksWithLimit RPC method allows you to retrieve a list of confirmed block slot numbers, starting from a specified slot and returning up to a given limit. This is useful when you need a specific number of subsequent confirmed blocks from a certain point in the ledger.
Common Use Cases
- Fetching a Fixed Number of Subsequent Blocks: Get a defined number of block slots that were confirmed after a particular start slot.
- Paginated Block Exploration: Retrieve blocks in chunks when analyzing a segment of the blockchain.
- Recent Block Monitoring: Get the last N blocks from a known recent slot.
Request Parameters
ThegetBlocksWithLimit method takes the following parameters:
start_slot(u64, required): The first slot to consider (inclusive).limit(u64, required): The maximum number of block slots to return. The total number of slots queried (fromstart_slotup tolimitblocks after it) must not exceed 500,000 slots.commitment(string, optional): Specifies the commitment level for the query. If omitted, the default commitment of the node is used. This is passed as the sole field in a configuration object as the last parameter.
Response Structure
Theresult field of the JSON-RPC response will be an array of u64 integers. Each integer in the array represents a confirmed block slot number, starting from start_slot up to the specified limit.
- Example: If
start_slotis 5 andlimitis 3, a possible result is[5, 6, 7].
Examples
1. Get a Limited Number of Blocks from a Start Slot
This example fetches a list of up to 5 confirmed block slots starting from slot280000000.
2. Get Blocks With Limit and a Specific Commitment Level
This example fetches up to 3 blocks starting from slot290000000 using the confirmed commitment level.
Developer Tips
- Range Clarification: The
limitparameter dictates the maximum number of block slots to return. The 500,000 slot constraint applies to the conceptual range scanned (i.e., fromstart_slottostart_slot + limit - 1). Ensure this conceptual range doesn’t exceed 500,000 slots, even if fewer actual blocks are found and returned within that range. - Node Data Availability: Nodes may not retain information for all historical slots. A very old
start_slotmight return fewer blocks than the specifiedlimit, or an empty array, depending on the node’s ledger retention. - Block Confirmation: This method returns confirmed blocks. The exact set of blocks can vary slightly depending on the chosen
commitmentlevel and which node you query, especially for very recent slots. - Use Case Specificity:
getBlocksWithLimitis ideal when you know the starting point and need a fixed number of subsequent blocks. If you need all blocks in a known slot range,getBlocksmight be more appropriate.
getBlocksWithLimit RPC method to list a specific number of confirmed block slots on the Solana network.
Related Methods
getBlocks
Get all blocks within a slot range
getBlock
Get detailed information for a specific block