getBlocks RPC method allows you to retrieve a list of confirmed block slot numbers between a specified start slot and an optional end slot. This is useful when you need to know which blocks have been confirmed in a particular range without fetching the full content of each block.
Common Use Cases
- Identifying Confirmed Blocks in a Range: Quickly get a list of all block slots that were successfully confirmed between two points in the ledger.
- Iterating Through Blocks: Use the returned list of slots to subsequently fetch detailed information for each block using
getBlockif needed. - Basic Block Auditing: Verify block presence within a certain range.
Request Parameters
ThegetBlocks method takes the following parameters:
start_slot(u64, required): The first slot to consider for the range (inclusive).end_slot(u64, optional): The last slot to consider for the range (inclusive).- If not provided, the query will return blocks up to the latest confirmed slot from
start_slot. - The range between
start_slotandend_slot(or latest slot ifend_slotis omitted) must not exceed 500,000 slots.
- If not provided, the query will return blocks up to the latest confirmed slot from
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 within the specified range.
- Example:
[5, 6, 7, 8, 9, 10]
Examples
1. Get Blocks within a Specific Slot Range
This example fetches the list of confirmed block slots between slot250000000 and 250000010.
2. Get Blocks from a Start Slot to the Latest Confirmed Slot
This example fetches confirmed block slots starting from260000000 up to the latest block confirmed by the node (respecting the 500,000 slot range limit from the start slot).
3. Get Blocks with a Specific Commitment Level
This example fetches blocks using theconfirmed commitment level.
Developer Tips
- Range Limit: Remember the 500,000 slot range limit. Requesting a larger range will result in an error.
- Node Data Availability: Nodes may not retain information for all historical slots. Very old
start_slotvalues might return empty arrays or errors depending on the node’s configuration and 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. - Complement to
getBlock:getBlocksis often used as a first step to identify relevant block slots before usinggetBlockto retrieve the full details of individual blocks within that list. - Pagination Alternative: Since
getBlockshas a range limit, if you need to scan a very large portion of the chain, you’ll need to make multiple calls togetBlocks, chunking your desired total range into segments of 500,000 slots or less.
getBlocks RPC method to list confirmed block slots on the Solana network.
Related Methods
getBlock
Get detailed information for a specific block
getBlocksWithLimit
Get a fixed number of blocks starting from a slot