isBlockhashValid
Learn isBlockhashValid use cases, code examples, request parameters, response structure, and tips.
The isBlockhashValid
RPC method in CoinVera checks whether a given blockhash is still considered valid by the Solana network. Since blockhashes expire after approximately 150 slots (~1–2 minutes), this method helps ensure that a transaction referencing an older blockhash won't be rejected.
🛈 Version Note: This method is available in Solana v1.9+. For older nodes (v1.8 or earlier), use
getFeeCalculatorForBlockhash
to implicitly verify blockhash validity.
✅ Common Use Cases
Transaction Resubmission Before retrying a failed transaction, check if the original blockhash is still valid.
Delayed Signing/Submission If a transaction is prepared but submitted later, validate the blockhash to avoid errors.
Optimistic Transaction Scheduling Ensure a held blockhash is still valid before attempting to send a transaction.
🧾 Request Parameters
[
blockhash: string, // Required – base-58 encoded blockhash string
options?: {
commitment?: string, // Optional – "processed", "confirmed", or "finalized"
minContextSlot?: number // Optional – ensure node response is from a recent enough slot
}
]
blockhash (required): The blockhash to validate.
commitment (optional): Query the blockhash validity based on a specific network confirmation level.
minContextSlot (optional): Ensures the response is based on a slot at least this recent—useful to prevent stale data.
📦 Response Structure
{
"context": {
"slot": 221446650
},
"value": true
}
value: Boolean result —
true
if the blockhash is valid,false
if it has expired.context.slot: The slot at which this response was evaluated.
🧪 Example
Check if a Blockhash is Valid
{
"jsonrpc": "2.0",
"id": 1,
"method": "isBlockhashValid",
"params": [
"3bXZjQUZw3PyWHVb7fG7Yf6pDD6MiZf9j8nAy4DDWjXu",
{
"commitment": "finalized"
}
]
}
Code Examples
const fetch = require('node-fetch');
async function isBlockhashValid(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'isBlockhashValid',
"params": [
"GS2XJrxSKuDa8BLgvGjVTHpsijDkNs53BsJAZLXwgZx1",
{
"commitment": "confirmed",
"minContextSlot": 355397937
}
]
}),
});
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';
isBlockhashValid(RPC_URL);
Example Response
{
"jsonrpc": "2.0",
"result": {
"context": {
"apiVersion": "2.2.16",
"slot": 355412699
},
"value": false
},
"id": 1
}
💡 Developer Tips
Blockhash Expiry Blockhashes are valid for ~150 slots. If you’re unsure about age, fetch a fresh one using
getLatestBlockhash
.Use
minContextSlot
for Accuracy This prevents a stale node from incorrectly reporting a blockhash as valid.Legacy Support On nodes running Solana <v1.9, use:
getFeeCalculatorForBlockhash("<BLOCKHASH>")
If it fails, the blockhash is no longer valid.
Validation ≠Finality A valid blockhash doesn’t guarantee transaction success. Finality is achieved only once the transaction is confirmed at the desired commitment level.
The isBlockhashValid
method is a critical tool in time-sensitive transaction flows, helping developers avoid expired-blockhash errors and ensure smoother interactions on the Solana blockchain using CoinVera.
Last updated