Documentation index

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

JavaScript
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const packageDef = protoLoader.loadSync('geyser.proto', {
  keepCase: true, longs: String, enums: String, defaults: true, oneofs: true
});
const proto = grpc.loadPackageDefinition(packageDef).geyser;
const client = new proto.Geyser('88.216.36.108:10001', grpc.credentials.createInsecure());

const blockhash = 'EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N';

client.isBlockhashValid({ blockhash, commitment: 1 }, (err, response) => {
  if (err) { console.error('gRPC error:', err); return; }
  if (response.valid) {
    console.log('Blockhash is still valid -- safe to submit transaction');
  } else {
    console.log('Blockhash has expired -- fetch a new one before submitting');
  }
});

Rust

Rust
use yellowstone_grpc_client::GeyserGrpcClient;
use yellowstone_grpc_proto::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = GeyserGrpcClient::build_from_uri("http://88.216.36.108:10001")
        .connect()
        .await?;

    let blockhash = "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N";
    let response = client
        .is_blockhash_valid(blockhash.to_string(), Some(CommitmentLevel::Confirmed as i32))
        .await?;
    let result = response.into_inner();

    if result.valid {
        println!("Blockhash is still valid");
    } else {
        println!("Blockhash has expired -- re-fetch required");
    }

    Ok(())
}

Example Response

JSON
{
  "valid": true
}