getFeeForMessage
https://api.triport.io/v1/solReturns the fee, in lamports, that the network will charge to process a particular Solana message.
getFeeForMessage quotes the fee, in lamports, that the cluster will charge
to land a given transaction message. You pass a compiled, base-64-encoded
message (the transaction without its signatures), and the node computes the
fee against a recent fee schedule and the blockhash embedded in the message.
Use this to show users an estimated cost before they sign and submit a transaction. The fee depends on the message contents (number of signatures, any compute-budget instructions) and on the network's current fee state, so quote it close to submission time rather than caching it.
The blockhash inside the message must still be valid. If it has expired, the
node cannot price the message and value comes back null — re-fetch a recent
blockhash, rebuild the message, and call again.
Parameters
JSON-RPC params is a positional array: [message, config?].
messagestring (base-64)requiredconfigobjectoptionalcommitmentstringoptionalprocessed, confirmed, or finalized.minContextSlotintegeroptionalResponse
When the message's blockhash has expired, value is null:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"context": {
"slot": 348392041,
"apiVersion": "2.0.18"
},
"value": null
}
}resultobjectRpcResponseU64 envelope.result.contextobjectresult.context.slotintegerresult.context.apiVersionstringresult.valueinteger | nullnull if the message's blockhash has expired.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 | message is missing, not valid base-64, not a decodable compiled message, or config is malformed. |
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). |
A successful call whose message blockhash has expired is not an error — it
returns result.value: null. Always null-check value before using it.
Examples
JavaScript (fetch)
const message = "AQABAgIAAAAMAAAAAAAAAA=="; // base-64 compiled message
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: "getFeeForMessage",
params: [message, { commitment: "confirmed" }],
}),
});
const { result } = await res.json();
if (result.value === null) {
console.warn("Blockhash expired — rebuild the message with a fresh blockhash.");
} else {
console.log(`Fee: ${result.value} lamports (${result.value / 1e9} SOL)`);
}TypeScript SDK (@triport/sdk)
import { TriportClient } from "@triport/sdk";
const client = new TriportClient({ apiKey: process.env.TRIPORT_API_KEY });
const message = "AQABAgIAAAAMAAAAAAAAAA=="; // base-64 compiled message
const { context, value } = await client.solana.getFeeForMessage(message, {
commitment: "confirmed",
});
if (value === null) {
throw new Error("Message blockhash expired; fetch a fresh blockhash and retry.");
}
console.log(`Fee: ${value} lamports (slot ${context.slot})`);Python (triport-sdk)
import os
from triport import TriportClient
client = TriportClient(api_key=os.environ["TRIPORT_API_KEY"])
message = "AQABAgIAAAAMAAAAAAAAAA==" # base-64 compiled message
result = client.solana.get_fee_for_message(message, commitment="confirmed")
if result["value"] is None:
raise RuntimeError("Message blockhash expired; rebuild with a fresh blockhash.")
print(f"Fee: {result['value']} lamports (slot {result['context']['slot']})")Notes
- Message, not transaction: the input is a compiled message (base-64), not a fully signed wire-format transaction. Encode the message bytes your signing library produces before sending it.
nullmeans expired blockhash: anullvalueis the documented signal that the blockhash baked into the message is no longer recent enough to price. Re-fetch a recent blockhash, rebuild the message, and call again.- Lamports, not SOL:
valueis an integer count of lamports. Divide by1e9to display a SOL figure. - Quote late: fees can change with network conditions; request the quote just before signing rather than caching it.
- Related methods: pair with
getLatestBlockhashto obtain a fresh blockhash for the message, andsendTransactionto submit the signed transaction once the fee is acceptable.