isBlockhashValid
Returns whether a blockhash is still valid at the requested commitment.
Request
Send a JSON-RPC 2.0 POST request with method: "isBlockhashValid". The params array takes a base-58 encoded blockhash string and an optional configuration object.
curl · JSON-RPCjson
{ "jsonrpc": "2.0", "id": 45, "method": "isBlockhashValid", "params": [ "J7rBdM6AecPDEZp8aPq5iPSNKVkU5Q76F3oAV4eW5wsW", { "commitment": "processed" } ]}@solana/kit
kit.tsts
import { createSolanaRpc, type Blockhash } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";const rpc = createSolanaRpc(rpc_url); let blockhash = "J7rBdM6AecPDEZp8aPq5iPSNKVkU5Q76F3oAV4eW5wsW"; let isValid = await rpc.isBlockhashValid(blockhash as Blockhash).send(); console.log(isValid);@solana/web3.js
web3.tsts
import { Connection } from "@solana/web3.js"; const connection = new Connection("https://rpc.openinfra.sh", "confirmed"); let blockhash = "J7rBdM6AecPDEZp8aPq5iPSNKVkU5Q76F3oAV4eW5wsW"; let isValid = await connection.isBlockhashValid(blockhash); console.log(isValid);Rust
main.rsrs
use anyhow::Result;use solana_client::nonblocking::rpc_client::RpcClient;use solana_commitment_config::CommitmentConfig;use solana_sdk::hash::Hash;use std::str::FromStr; #[tokio::main]async fn main() -> Result<()> { let client = RpcClient::new_with_commitment( String::from("https://rpc.openinfra.sh"), CommitmentConfig::confirmed(), ); let blockhash = Hash::from_str("J7rBdM6AecPDEZp8aPq5iPSNKVkU5Q76F3oAV4eW5wsW")?; let is_valid = client .is_blockhash_valid(&blockhash, CommitmentConfig::finalized()) .await?; println!("{:#?}", is_valid); Ok(())}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| blockhash | string | Yes | The blockhash of the block to evaluate, as a base-58 encoded string. |
| config | object | No | Optional configuration object. See fields below. |
| config.commitment | string | No | Desired finality level for the query. Accepted values: processed, confirmed, finalized (default). |
| config.minContextSlot | number | No | The minimum slot at which the request may be evaluated. |
commitment values
| Value | Description |
|---|---|
| processed | Return 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. |
| confirmed | Return data from the highest slot that at least two-thirds of active stake has directly voted to confirm. More stable than processed, but a weaker guarantee than finalized. |
| finalized | Return data from the highest slot that the cluster recognizes as finalized. 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": 2483 }, "value": false }, "id": 45}The result is an RpcResponse object with two fields:
| Field | Type | Description |
|---|---|---|
| context | object | Slot and API version the node used to answer this request. |
| context.slot | u64 | Slot at which the node evaluated this request. |
| context.apiVersion | string | RPC API version reported by the node. This field may be omitted by older nodes. |
| value | bool | Whether the blockhash is still valid at the evaluated slot. |