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

OpenInfra.shopeninfra.sh

getLatestBlockhash

Returns the latest recent blockhash and its last valid block height.

Request

Send a JSON-RPC 2.0 POST request with method: "getLatestBlockhash". The params array takes an optional configuration object.

curl · JSON-RPCjson
{  "jsonrpc": "2.0",  "id": 1,  "method": "getLatestBlockhash",  "params": [    {      "commitment": "processed"    }  ]}

@solana/kit

kit.tsts
import { createSolanaRpc, type Commitment } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";const rpc = createSolanaRpc(rpc_url); let commitment: Commitment = "processed";let latestBlockhash = await rpc.getLatestBlockhash({ commitment }).send(); console.log(latestBlockhash);

@solana/web3.js

web3.tsts
import { Connection, type Commitment } from "@solana/web3.js"; const connection = new Connection("https://rpc.openinfra.sh", "confirmed"); let commitment: Commitment = "processed";let latestBlockhash = await connection.getLatestBlockhash(commitment); console.log(latestBlockhash);

Rust

main.rsrs
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 commitment = CommitmentConfig::processed();    let latest_blockhash = client        .get_latest_blockhash_with_commitment(commitment)        .await?;     println!("{:#?}", latest_blockhash);     Ok(())}

Parameters

ParameterTypeRequiredDescription
configobjectNoOptional configuration object. See fields below.
config.commitmentstringNoDesired finality level for the query. Accepted values: processed, confirmed, finalized (default).
config.minContextSlotnumberNoThe minimum slot at which the request may be evaluated.

commitment values

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. This is more stable than processed, but it is still a weaker guarantee than finalized.
finalizedReturn data from the highest slot that the cluster recognizes as finalized. In practice, this means 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

{ "minContextSlot": 341197000 }

Response

response.jsonjson
{  "jsonrpc": "2.0",  "result": {    "context": {      "apiVersion": "3.1.8",      "slot": 2792    },    "value": {      "blockhash": "EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N",      "lastValidBlockHeight": 3090    }  },  "id": 1}

The result is an RpcResponse object with two top-level fields:

FieldTypeDescription
contextobjectSlot and API version the node used to answer this request.
context.slotu64Slot at which the node evaluated this request.
context.apiVersionstringRPC API version reported by the node. This field may be omitted by older nodes.
valueobjectLatest blockhash response object.
value.blockhashstringLatest blockhash, as a base-58 encoded string.
value.lastValidBlockHeightu64Last block height at which this blockhash remains valid.