OpenInfra.sh is now live - Solana infrastructure, included with every server. LEARN MORE HERE >

OpenInfra.shopeninfra.sh

getBlockHeight

Returns the block height the node sees at the requested commitment.

Request

{  "jsonrpc": "2.0",  "id": 1,  "method": "getBlockHeight",  "params": [    {      "commitment": "finalized"    }  ]}

Parameters

ParameterTypeRequiredDescription
configobjectNoConfiguration object with optional commitment and minContextSlot fields.
config.commitmentstringNoDesired commitment level for the response: processed, confirmed, or finalized. Default: finalized.
config.minContextSlotnumberNoThe minimum slot that the request can be evaluated at.

Commitment levels

ValueDescription
processedReturn data from the highest slot this node has processed on the fork it currently considers best. This is the newest view, but it can still change if the cluster switches forks.
confirmedReturn data from the highest slot that at least two-thirds of active stake has directly voted to confirm. More stable than processed, but still a weaker guarantee than finalized.
finalizedReturn data from the highest slot that the cluster recognizes as finalized. In practice, the slot has reached maximum vote lockout in validators' vote towers and is recognized by at least two-thirds of active stake. This is the strongest commitment level.

minContextSlot example

Examplejson
{ "minContextSlot": 341197000 }

Response

{  "jsonrpc": "2.0",  "result": 1233,  "id": 1}
FieldTypeDescription
resultu64Block height the node used to answer this request.

Code examples

@solana/kit

kit.tsts
import { createSolanaRpc } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";const rpc = createSolanaRpc(rpc_url); let blockHeight = await rpc.getBlockHeight().send(); console.log("block height:", blockHeight);

@solana/web3.js

web3js.tsts
import { Connection } from "@solana/web3.js"; const connection = new Connection("https://rpc.openinfra.sh", "confirmed"); let blockHeight = await connection.getBlockHeight(); console.log("block height:", blockHeight);

Rust

main.rsrust
use anyhow::Result;use solana_client::nonblocking::rpc_client::RpcClient;use solana_commitment_config::CommitmentConfig; #[tokio::main]async fn main() -> Result<()> {    let client = RpcClient::new_with_commitment(        String::from("https://rpc.openinfra.sh"),        CommitmentConfig::confirmed(),    );     let block_height = client.get_block_height().await?;     println!("Block height: {:#?}", block_height);     Ok(())}

Notes