GetLatestBlockhash
Returns the latest blockhash and the last valid block height for transaction signing.
Type: unary
Overview
GetLatestBlockhash retrieves the most recent blockhash from the cluster along with the last valid block height. This is essential for constructing and signing transactions, as Solana transactions require a recent blockhash to be considered valid.
For HFT and MEV applications, having a fresh blockhash with minimal latency is critical. Using a stale blockhash will result in transaction failures. This gRPC method provides faster access compared to the equivalent JSON-RPC call.
Parameters
| Name | Type | Description |
|---|---|---|
| commitment | CommitmentLevel | Optional. The commitment level: processed, confirmed, or finalized. |
Response
| Field | Type | Description |
|---|---|---|
| blockhash | string | The latest blockhash as a base-58 encoded string |
| last_valid_block_height | uint64 | The last block height at which the blockhash will be valid |
| slot | uint64 | The slot in which the blockhash was produced |
Usage 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({}, (err, response) => {
11 if (err) { console.error(err); return; }
12 console.log('Response:', response);
13});Rust
1use yellowstone_grpc_proto::geyser::geyser_client::GeyserClient;
2use tonic::transport::Channel;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let channel = Channel::from_static("http://[IP_ADDRESS]:[PORT]")
7 .connect().await?;
8 let mut client = GeyserClient::new(channel);
9
10 let response = client.getLatestBlockhash(tonic::Request::new(())).await?;
11 println!("Response: {:?}", response.into_inner());
12
13 Ok(())
14}