getFirstAvailableBlock
Learn getFirstAvailableBlock use cases, code examples, request parameters, response structure, and tips.
The getFirstAvailableBlock
RPC method returns the slot number of the oldest confirmed block still retained in the ledger by the queried RPC node. This is helpful for understanding how much historical block data a node currently stores and where its ledger history begins.
β
Common Use Cases
Historical Data Access Identify the earliest slot from which you can query confirmed block or transaction data using methods like
getBlock
,getTransaction
, orgetConfirmedSignaturesForAddress2
.Evaluate Ledger Retention Understand the storage configuration and pruning behavior of a specific nodeβuseful for analytics tools or explorers.
Cross-Node Comparison While not a direct measure of synchronization, comparing results from different nodes can indicate which ones retain deeper historical data.
π Request Parameters
This method does not require any parameters.
π¦ Response Structure
The result
field returns a single value:
{
"jsonrpc": "2.0",
"result": 12345678,
"id": 1
}
result
(u64):
The slot number of the first available confirmed block on the node.
π‘ Example: Get First Available Block Slot
{
"jsonrpc": "2.0",
"id": 1,
"method": "getFirstAvailableBlock"
}
Code Examples
const fetch = require('node-fetch');
async function getFirstAvailableBlock(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getFirstAvailableBlock'
}),
});
const data = await response.json();
// Print the exact full response
console.log('Full RPC Response:');
console.log(JSON.stringify(data, null, 2));
return data;
} catch (error) {
console.error('Error getting health:', error.message);
return null;
}
}
// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';
getFirstAvailableBlock(RPC_URL);
Example Response
{
"jsonrpc": "2.0",
"result": 0,
"id": 1
}
π§ Developer Tips
Node-Specific Results Each RPC node has its own ledger retention policy. Some nodes (e.g., archival nodes) may retain millions of slots, while others prune older data more aggressively.
Continuously Increases The returned slot number will increase over time as older blocks are pruned to conserve disk space.
Confirmed Blocks Only This method returns the first confirmed block still available. It does not reflect processed or unconfirmed slots.
Use in Data Pipelines Ideal for setting the lower bound when scanning transaction histories or backfilling analytics data.
Last updated