The 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 getBlock if needed.
  • Basic Block Auditing: Verify block presence within a certain range.

Request Parameters

The getBlocks method takes the following parameters:

  1. start_slot (u64, required): The first slot to consider for the range (inclusive).
  2. 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_slot and end_slot (or latest slot if end_slot is omitted) must not exceed 500,000 slots.
  3. 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

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 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 slot 250000000 and 250000010.

curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
  '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getBlocks",
    "params": [
      250000000,
      250000010
    ]
  }'

2. Get Blocks from a Start Slot to the Latest Confirmed Slot

This example fetches confirmed block slots starting from 260000000 up to the latest block confirmed by the node (respecting the 500,000 slot range limit from the start slot).

curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
  '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getBlocks",
    "params": [
      260000000 
    ]
  }'

3. Get Blocks with a Specific Commitment Level

This example fetches blocks using the confirmed commitment level.

curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
  '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getBlocks",
    "params": [
      270000000,
      270000005,
      { "commitment": "confirmed" }
    ]
  }'

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_slot values 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 commitment level and which node you query, especially for very recent slots.
  • Complement to getBlock: getBlocks is often used as a first step to identify relevant block slots before using getBlock to retrieve the full details of individual blocks within that list.
  • Pagination Alternative: Since getBlocks has a range limit, if you need to scan a very large portion of the chain, you’ll need to make multiple calls to getBlocks, chunking your desired total range into segments of 500,000 slots or less.

This guide provides a clear overview of how to use the getBlocks RPC method to list confirmed block slots on the Solana network.