getBlocks
Returns a list of confirmed blocks between two slots
Common use cases
| Block range scanning | Retrieve slot numbers for confirmed blocks in a range to process historical blockchain data. Common for indexers, explorers, and analytics platforms tracking transactions over time. |
| Missing slot detection | Identify skipped slots by detecting gaps in returned slot array. Used for network health monitoring and data completeness validation in blockchain infrastructure. |
| Historical transaction discovery | Find all blocks containing transactions for subsequent retrieval with getBlock. Essential for account history reconstruction and transaction tracking across slot ranges. |
| Blockchain synchronization | Continuously fetch new blocks by polling getBlocks with incrementing start_slot ranges. Used by lightweight clients and services maintaining real-time blockchain state. |
| Finalization monitoring | Track block finality by querying with finalized commitment level to confirm which blocks have reached immutable state. Critical for applications requiring irreversibility guarantees. |
Parameters
start slot (u64, required)
Start slot
end slot (u64, optional)
End slot (must be no more than 500,000 blocks higher than the start_slot)
options (object, optional)
Configuration object
Fields:
commitment(string): The commitment describes how finalized a block is at that point in time. See Configuring State Commitment.- "processed" is not supported
Request
- cURL
- JavaScript
- Python
curl https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [
5,
10,
{
"commitment": "finalized"
}
]
}'
// Using fetch
const response = await fetch('https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [
5,
10,
{
"commitment": "finalized"
}
]
})
});
const data = await response.json();
console.log(data);
import requests
import json
url = 'https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "getBlocks",
"params": [
5,
10,
{
"commitment": "finalized"
}
]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
Replace mainnet with devnet in the URL to query devnet instead.
Response
{
"jsonrpc": "2.0",
"result": [5, 6, 7, 8, 9, 10],
"id": 1
}
Response Fields
Return value: array
An array of u64 integers listing confirmed blocks between start_slot and either end_slot - if provided, or latest confirmed slot, inclusive. Max range allowed is 500,000 slots.
FAQ and Troubleshooting
Why does getBlocks return an array with gaps (e.g., [5, 7] instead of [5, 6, 7])?
Gaps indicate skipped slots where no block was produced. This occurs when the leader validator is offline, behind the network, experiences interruptions from a previous leader, or produces a block on a minority fork. This is expected Solana behavior and not an RPC error.
Why do I get "Slot XXX was skipped, or missing in long-term storage" (error -32009)?
Error -32009 indicates the slot was either skipped (no block produced) or the RPC node's historical archive doesn't have data for that slot. For recent slots, verify the node is synced. For very old slots, check if the RPC provider maintains complete history or consider archival RPC services.
What happens if I exceed the 500,000 slot range limit?
The RPC returns an error (typically RpcError::RpcRequestError). To query larger ranges, split the request into multiple calls with 500k slot chunks and aggregate results. Use getBlocksWithLimit for simpler pagination.
How do I efficiently scan all historical blocks from genesis?
Iterate in 500k slot batches: fetch getBlocks(start, start+500k), process returned slots, increment start by 500k, repeat. Use getSlot to find current slot as upper bound. For better performance, parallelize requests for non-overlapping ranges.
Should I use processed, confirmed, or finalized commitment for getBlocks?
Use finalized for applications requiring irreversibility (exchanges, settlement systems). Use confirmed for lower latency when recent forks are acceptable (explorers, monitoring dashboards). processed is rarely needed for getBlocks since block lists are typically used for historical or near-finalized data.
Related Methods
getBlock
Retrieves complete block data (transactions, rewards, metadata) for a specific slot. Use getBlocks to find slot numbers, then getBlock to fetch full block details for each slot.
getBlocksWithLimit
Similar to getBlocks but accepts a limit parameter instead of end_slot, returning up to the specified number of blocks. Simpler pagination for sequential scanning without tracking exact end slots.
getSlot
Returns the current slot number at specified commitment level. Use before getBlocks to determine the upper bound for block range queries.
blockSubscribe (WebSocket)
Real-time alternative to polling getBlocks. Subscribe to new blocks as they're produced instead of repeatedly calling getBlocks for recent ranges.
getBlockTime
Returns estimated production time for a block slot. Complement to getBlocks for applications needing temporal ordering of historical blocks.
External Resources
- Solana Official Documentation
- Solana Cookbook: Developer Guides - Official developer guides covering RPC usage patterns and blockchain data retrieval best practices.
- CryptoDataBytes: Solana Data RPC Guide - Community tutorial analyzing Solana blockchain data using RPC methods including block retrieval patterns.