in-solana by Supanode

isBlockhashValid — Solana RPC Method

isBlockhashValid checks whether a specific blockhash is still valid for transaction submission. This is useful when you have a pre-built transaction and want to verify its blockhash has not expired before sending.

Parameters

NameTypeRequiredDescription
blockhashstringYesBase-58 encoded blockhash to check.
commitmentstringNoprocessed, confirmed, or finalized. Default: finalized.
minContextSlotnumberNoMinimum slot at which the request can be evaluated.

Request

curl -X POST https://api.mainnet-beta.solana.com \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "isBlockhashValid",
    "params": [
      "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N",
      {"commitment": "finalized"}
    ]
  }'

TypeScript (@solana/kit)

import { createSolanaRpc } from "@solana/kit";

const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
const { value } = await rpc
  .isBlockhashValid("EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N", {
    commitment: "finalized",
  })
  .send();

console.log(`Blockhash valid: ${value}`);

Response

{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 341200000, "apiVersion": "2.2.4" },
    "value": true
  },
  "id": 1
}
FieldTypeDescription
valuebooltrue if the blockhash is still valid, false if it has expired.

Common errors

  • Invalid blockhash format — a malformed base-58 string returns a parse error.

Performance

Lightweight check against the node’s blockhash cache. Fast to call.

FAQ

How long is a blockhash valid? Approximately 60-90 seconds, or roughly 150 blocks. The exact duration depends on block production speed.

When should I use isBlockhashValid? When you have a pre-signed transaction and want to check if its blockhash is still valid before sending. If it has expired, you need to rebuild and re-sign the transaction with a fresh blockhash.

What commitment level should I use? Use the same commitment level you used when fetching the blockhash. A blockhash fetched with finalized commitment should be checked with finalized.

Can a valid blockhash become invalid between my check and send? Yes. The blockhash can expire at any moment. Check and send as close together as possible, or be prepared to retry with a fresh blockhash.

What is the difference between this and checking lastValidBlockHeight? Both work. isBlockhashValid checks the blockhash directly. Checking lastValidBlockHeight from getLatestBlockhash against the current block height from getBlockHeight achieves the same thing but requires two calls.

Parameters

ParameterTypeRequiredDescriptionDefault
blockhashstringYesBase-58 encoded blockhash to check.—
commitmentstringNoCommitment level: processed, confirmed, or finalized.finalized
minContextSlotnumberNoMinimum slot at which the request can be evaluated.—

Updated: