TriportRPC

getLatestBlockhash

Last updated:

`getLatestBlockhash` returns a recent **blockhash** that you embed into a transaction message before signing, together with the `lastValidBlockHeight` — the highest block height at which a transaction built on that blockhash will still be accepted by the cluster.

This method is a required step in nearly every transaction-building flow. A Solana transaction must reference a recent blockhash to be valid; the cluster rejects transactions whose blockhash is too old. Fetch a fresh blockhash immediately before constructing and signing, then submit the signed transaction via [`sendTransaction`](./sendTransaction.md).

**The blockhash expires.** Once the cluster's block height climbs past `lastValidBlockHeight`, the blockhash is no longer accepted and the transaction can never land. Use `lastValidBlockHeight` to drive confirmation polling and retry logic: keep re-submitting until the transaction confirms or the current block height (from [`getBlockHeight`](./getBlockHeight.md)) exceeds the returned `lastValidBlockHeight`, at which point you should fetch a new blockhash and rebuild.

Parameters

getLatestBlockhash parameters
NameTypeRequiredDescription
configCommitmentConfigNo

Returns

getLatestBlockhash return value
FieldType
resultobject

Examples

curl https://<your-endpoint>/ \
  -X POST -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"getLatestBlockhash","params":[]}'
const res = await fetch("https://<your-endpoint>/", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "id": 1,
  "method": "getLatestBlockhash",
  "params": [],
  "jsonrpc": "2.0"
}),
});
const data = await res.json();
import requests
resp = requests.post("https://<your-endpoint>/", json={"id":1,"method":"getLatestBlockhash","params":[],"jsonrpc":"2.0"})
print(resp.json())

Usage

  1. Transport: HTTP (JSON-RPC).
  2. Networks: mainnet, devnet, testnet.
  3. Credit cost: 1 per call.

FAQ

What does getLatestBlockhash do?
Returns the latest blockhash along with the last block height at which it remains valid for signing transactions.
How many credits does getLatestBlockhash cost?
getLatestBlockhash costs 1 credit(s) per call on Triport by default.
Is getLatestBlockhash available over WebSocket?
getLatestBlockhash is an HTTP JSON-RPC method.