IsBlockhashValid

Checks whether a given blockhash is still valid for transaction submission. Blockhashes on Solana expire after approximately 150 blocks (~1 minute). This is the gRPC equivalent of the JSON-RPC isBlockhashValid method.

Use this method to verify that a previously fetched blockhash has not expired before signing and submitting a transaction. This is critical for trading bots that pre-compute transactions and need to confirm the blockhash is still usable at send time, avoiding wasted compute and failed submissions.

Type: Unary (request/response)

Parameters

ParameterTypeRequiredDescription
blockhashstringYesThe blockhash to check, as a base-58 encoded string
commitmentCommitmentLevelNoCommitment level: Processed (0), Confirmed (1), or Finalized (2). Default: Finalized

Response

FieldTypeDescription
validbooltrue if the blockhash is still valid for transaction submission, false otherwise

Code Examples

Node.js

1const grpc = require('@grpc/grpc-js');
2const protoLoader = require('@grpc/proto-loader');
3
4const packageDef = protoLoader.loadSync('geyser.proto', {
5  keepCase: true, longs: String, enums: String, defaults: true, oneofs: true
6});
7const proto = grpc.loadPackageDefinition(packageDef).geyser;
8const client = new proto.Geyser('[IP_ADDRESS]:[PORT]', grpc.credentials.createInsecure());
9
10const blockhash = 'EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N';
11
12client.isBlockhashValid({ blockhash, commitment: 1 }, (err, response) => {
13  if (err) { console.error('gRPC error:', err); return; }
14  if (response.valid) {
15    console.log('Blockhash is still valid -- safe to submit transaction');
16  } else {
17    console.log('Blockhash has expired -- fetch a new one before submitting');
18  }
19});

Rust

1use yellowstone_grpc_client::GeyserGrpcClient;
2use yellowstone_grpc_proto::prelude::*;
3
4#[tokio::main]
5async fn main() -> anyhow::Result<()> {
6    let mut client = GeyserGrpcClient::build_from_uri("http://[IP_ADDRESS]:[PORT]")
7        .connect()
8        .await?;
9
10    let blockhash = "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N";
11    let response = client
12        .is_blockhash_valid(blockhash.to_string(), Some(CommitmentLevel::Confirmed as i32))
13        .await?;
14    let result = response.into_inner();
15
16    if result.valid {
17        println!("Blockhash is still valid");
18    } else {
19        println!("Blockhash has expired -- re-fetch required");
20    }
21
22    Ok(())
23}

Example Response

1{
2  "valid": true
3}