TriportRPC

getLatestBlockhash

POSThttps://api.triport.io/v1/sol

Returns the latest blockhash along with the last block height at which it remains valid for signing transactions.

Solanasol_read_rpcfree+ — 20 / 60 / 200 / 600 RPS (free / basic / pro / business)

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.

configobjectoptional
Optional configuration object (see below).
commitmentstringoptional
Commitment level: processed, confirmed, or finalized.
minContextSlotintegeroptional
Minimum slot the request must be evaluated at.

Response

Response fields

FieldTypeDescription
resultobjectLatestBlockhashResponse envelope.
result.contextobjectThe context the response was evaluated against.
result.context.slotintegerThe slot at which the blockhash was read.
result.context.apiVersionstringThe node software version that served the request.
result.valueobjectThe blockhash payload.
result.value.blockhashstring (base-58)A recent blockhash to embed in your transaction message.
result.value.lastValidBlockHeightintegerThe 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.

CodeMeaningWhen it happens
-32602Invalid paramsconfig is malformed, or commitment is not one of processed / confirmed / finalized.
401UnauthorizedMissing or invalid Authorization: Bearer key.
429Rate limitedMore 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: poll getBlockHeight while awaiting confirmation. Once the current height passes lastValidBlockHeight, the transaction can no longer land — fetch a fresh blockhash and rebuild rather than continuing to retry.
  • Commitment matters: a finalized blockhash is the most durable but slightly older; confirmed or processed give 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 sendTransaction to submit the signed transaction, getFeeForMessage to price a message before signing, and getBlockHeight to track expiry.