Documentation index

GetLatestBlockhash

Returns the latest blockhash that the node has processed. This is the gRPC equivalent of the JSON-RPC getLatestBlockhash method, providing the same data with significantly lower latency through the Yellowstone Geyser plugin.

Every Solana transaction requires a recent blockhash to be valid. Use this method to fetch one before signing and submitting transactions. For HFT and MEV applications, having the freshest possible blockhash is critical to avoid transaction expiration and maximize execution speed.

Type: Unary (request/response)

Parameters

ParameterTypeRequiredDescription
commitmentCommitmentLevelNoCommitment level: Processed (0), Confirmed (1), or Finalized (2). Default: Finalized

Response

FieldTypeDescription
blockhashstringThe latest blockhash as a base-58 encoded string
last_valid_block_heightuint64The last block height at which the blockhash is valid

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());

client.getLatestBlockhash({ commitment: 1 }, (err, response) => {
  if (err) { console.error('gRPC error:', err); return; }
  console.log('Blockhash:', response.blockhash);
  console.log('Last valid block height:', response.last_valid_block_height);
});

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 response = client
        .get_latest_blockhash(Some(CommitmentLevel::Confirmed as i32))
        .await?;
    let blockhash = response.into_inner();
    println!("Blockhash: {}", blockhash.blockhash);
    println!("Last valid block height: {}", blockhash.last_valid_block_height);

    Ok(())
}

Example Response

JSON
{
  "blockhash": "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N",
  "last_valid_block_height": "123456789"
}