GetBlockHeight
Returns the current block height that the node has processed. Block height is a monotonically increasing counter that increments with each new block, unlike slot numbers which can be skipped. This is the gRPC equivalent of the JSON-RPC getBlockHeight method.
Use block height to track chain progression, determine transaction finality windows, and verify that your node is keeping up with the network. Combined with GetLatestBlockhash, it helps you calculate how many blocks remain before a blockhash expires.
Type: Unary (request/response)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
commitment | CommitmentLevel | No | Commitment level: Processed (0), Confirmed (1), or Finalized (2). Default: Finalized |
Response
| Field | Type | Description |
|---|---|---|
block_height | uint64 | The current block height at the requested commitment level |
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
10// Get block height at Finalized commitment
11client.getBlockHeight({ commitment: 2 }, (err, response) => {
12 if (err) { console.error('gRPC error:', err); return; }
13 console.log('Current block height:', response.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_block_height(Some(CommitmentLevel::Finalized as i32))
12 .await?;
13 let result = response.into_inner();
14 println!("Current block height: {}", result.block_height);
15
16 Ok(())
17}Example Response
1{
2 "block_height": "230000042"
3}