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

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
10client.getLatestBlockhash({ commitment: 1 }, (err, response) => {
11  if (err) { console.error('gRPC error:', err); return; }
12  console.log('Blockhash:', response.blockhash);
13  console.log('Last valid block height:', response.last_valid_block_height);
14});

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

Example Response

1{
2  "blockhash": "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N",
3  "last_valid_block_height": "123456789"
4}