getLatestBlockhash
https://api.triport.io/v1/solReturns the latest blockhash along with the last block height at which it remains valid for signing transactions.
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.
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) exceeds the returned
lastValidBlockHeight, at which point you should fetch a new blockhash and
rebuild.
Parameters
JSON-RPC params is a positional array: [config?]. The single parameter is
an optional configuration object.
configobjectoptionalcommitmentstringoptionalprocessed, confirmed, or finalized.minContextSlotintegeroptionalResponse
Response fields
| Field | Type | Description |
|---|---|---|
result | object | LatestBlockhashResponse envelope. |
result.context | object | The context the response was evaluated against. |
result.context.slot | integer | The slot at which the blockhash was read. |
result.context.apiVersion | string | The node software version that served the request. |
result.value | object | The blockhash payload. |
result.value.blockhash | string (base-58) | A recent blockhash to embed in your transaction message. |
result.value.lastValidBlockHeight | integer | The last block height at which a transaction using this blockhash is still valid. |
Errors
Errors are returned in the standard JSON-RPC error envelope. See the shared errors reference for the full envelope shape and shared codes.
| Code | Meaning | When it happens |
|---|---|---|
-32602 | Invalid params | config is malformed, or commitment is not one of processed / confirmed / finalized. |
401 | Unauthorized | Missing or invalid Authorization: Bearer key. |
429 | Rate limited | More than your tier's RPS for sol_read_rpc (20 / 60 / 200 / 600). |
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/sol", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getLatestBlockhash",
params: [{ commitment: "finalized" }],
}),
});
const { result } = await res.json();
const { blockhash, lastValidBlockHeight } = result.value;
console.log(`Blockhash ${blockhash} valid until block ${lastValidBlockHeight}`);TypeScript SDK (@triport/sdk)
import { TriportClient } from "@triport/sdk";
const client = new TriportClient({ apiKey: process.env.TRIPORT_API_KEY });
const { context, value } = await client.solana.getLatestBlockhash({
commitment: "finalized",
});
console.log(
`Blockhash ${value.blockhash} (slot ${context.slot}) ` +
`valid until block ${value.lastValidBlockHeight}`
);Python (triport-sdk)
import os
from triport import TriportClient
client = TriportClient(api_key=os.environ["TRIPORT_API_KEY"])
result = client.solana.get_latest_blockhash(commitment="finalized")
value = result["value"]
print(
f"Blockhash {value['blockhash']} "
f"valid until block {value['lastValidBlockHeight']}"
)Notes
- Fetch late, sign immediately: request the blockhash as close as possible to signing and submitting. The older the blockhash, the less of its validity window remains.
- Drive retries with
lastValidBlockHeight: pollgetBlockHeightwhile awaiting confirmation. Once the current height passeslastValidBlockHeight, the transaction can no longer land — fetch a fresh blockhash and rebuild rather than continuing to retry. - Commitment matters: a
finalizedblockhash is the most durable but slightly older;confirmedorprocessedgive you a more recent blockhash at the cost of a small chance of referencing a dropped fork. When omitted, the node's default commitment applies. - Related methods: pair with
sendTransactionto submit the signed transaction,getFeeForMessageto price a message before signing, andgetBlockHeightto track expiry.