Learn getBlocksWithLimit use cases, code examples, request parameters, response structure, and tips.
The 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.
Avoid Batching for Better PerformanceBatching archival methods significantly increases latency. Batches over 10 requests are not allowed.
The getBlocksWithLimit 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 (from start_slot up to limit blocks 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.
The result 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_slot is 5 and limit is 3, a possible result is [5, 6, 7].
Range Clarification: The limit parameter dictates the maximum number of block slots to return. The 500,000 slot constraint applies to the conceptual range scanned (i.e., from start_slot to start_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_slot might return fewer blocks than the specified limit, 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 commitment level and which node you query, especially for very recent slots.
Use Case Specificity:getBlocksWithLimit is 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, getBlocks might be more appropriate.
This guide provides a clear overview of how to use the getBlocksWithLimit RPC method to list a specific number of confirmed block slots on the Solana network.