TriportRPC

getFeeForMessage

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

Returns the fee, in lamports, that the network will charge to process a particular Solana message.

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

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)required
A compiled transaction message, base-64 encoded. This is the message bytes only — not a signed, wire-format transaction.
configobjectoptional
Optional configuration object (see below).
commitmentstringoptional
Commitment level used to select the fee schedule: processed, confirmed, or finalized.
minContextSlotintegeroptional
Minimum slot the request must be evaluated at.

Response

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
  }
}
resultobject
RpcResponseU64 envelope.
result.contextobject
The context the response was evaluated against.
result.context.slotinteger
The slot at which the fee was computed.
result.context.apiVersionstring
The node software version that served the request.
result.valueinteger | null
The fee in lamports, or null 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.

CodeMeaningWhen it happens
-32602Invalid paramsmessage is missing, not valid base-64, not a decodable compiled message, or config is malformed.
401UnauthorizedMissing or invalid Authorization: Bearer key.
429Rate limitedMore 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.
  • null means expired blockhash: a null value is 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: value is an integer count of lamports. Divide by 1e9 to 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 getLatestBlockhash to obtain a fresh blockhash for the message, and sendTransaction to submit the signed transaction once the fee is acceptable.