Documentation index

getLatestBlockhash

Returns the latest blockhash and the last block height at which it will be valid. Every Solana transaction requires a recent blockhash to prevent replay attacks and ensure timeliness. This is one of the most frequently called methods in any Solana application, as it must be invoked before constructing and sending any transaction. The lastValidBlockHeight tells you when the blockhash expires.

Parameters

#TypeRequiredDescription
1objectNoConfiguration object

Configuration object fields:

FieldTypeDescription
commitmentstringCommitment level: processed, confirmed, or finalized
minContextSlotnumberMinimum slot at which the request can be evaluated

Response

Returns an RpcResponse object:

FieldTypeDescription
context.slotu64The slot at which the value was read
value.blockhashstringBase-58 encoded blockhash
value.lastValidBlockHeightu64Last block height at which the blockhash will be valid

Code Examples

cURL

Terminal
curl http://88.216.36.108:7999 -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getLatestBlockhash",
  "params": [
    { "commitment": "finalized" }
  ]
}'

TypeScript

TypeScript
const response = await fetch("http://88.216.36.108:7999", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getLatestBlockhash",
    params: [
      { commitment: "finalized" }
    ]
  }),
});
const { result } = await response.json();
console.log("Blockhash:", result.value.blockhash);

Python

Python
import requests

response = requests.post("http://88.216.36.108:7999", json={
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getLatestBlockhash",
    "params": [
        {"commitment": "finalized"}
    ]
})
result = response.json()["result"]
print(f"Blockhash: {result['value']['blockhash']}")

Rust

Rust
use reqwest::Client;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let res = client.post("http://88.216.36.108:7999")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getLatestBlockhash",
            "params": [
                {"commitment": "finalized"}
            ]
        }))
        .send().await?
        .text().await?;
    println!("{}", res);
    Ok(())
}

Example Response

JSON
{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 166974442 },
    "value": {
      "blockhash": "GJxqhuxcgfn5Tcj6y3f8X4FeCDd2RQ6SnEMo1AAxrPRZ",
      "lastValidBlockHeight": 150676181
    }
  },
  "id": 1
}