in-solana by Supanode

getFeeForMessage — Solana RPC Method

getFeeForMessage calculates the fee the network will charge for a specific transaction message. The fee depends on the number of signatures required by the message and the current fee schedule.

Parameters

NameTypeRequiredDescription
messagestringYesBase-64 encoded transaction message (the serialized Message portion of a transaction, not the full transaction).
commitmentstringNoprocessed, confirmed, or finalized. Default: finalized.
minContextSlotnumberNoMinimum slot at which the request can be evaluated.

Request

curl -X POST https://api.mainnet-beta.solana.com \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getFeeForMessage",
    "params": [
      "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
      {"commitment": "confirmed"}
    ]
  }'

TypeScript (@solana/kit)

import {
  createSolanaRpc,
  pipe,
  createTransactionMessage,
  setTransactionMessageFeePayer,
  setTransactionMessageLifetimeUsingBlockhash,
  appendTransactionMessageInstruction,
  compileTransactionMessage,
  getBase64EncodedWireTransaction,
  address,
} from "@solana/kit";

const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
const { value: blockhash } = await rpc.getLatestBlockhash().send();

const message = pipe(
  createTransactionMessage({ version: 0 }),
  (m) => setTransactionMessageFeePayer(address("Fee111..."), m),
  (m) => setTransactionMessageLifetimeUsingBlockhash(blockhash, m),
);

const compiled = compileTransactionMessage(message);
const encoded = getBase64EncodedWireTransaction(compiled);

const fee = await rpc
  .getFeeForMessage(encoded, { commitment: "confirmed" })
  .send();

console.log(`Fee: ${fee.value} lamports`);

Response

{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 341200000, "apiVersion": "2.2.4" },
    "value": 5000
  },
  "id": 1
}
FieldTypeDescription
valueu64 or nullFee in lamports for the message. null if the blockhash in the message has expired.

How fees are calculated

Solana transaction fees are based on the number of signatures required. The base fee is 5,000 lamports per signature. A standard transaction with one signer costs 5,000 lamports (0.000005 SOL). Multi-sig transactions cost 5,000 lamports per required signature.

Priority fees (set via the Compute Budget program) are additional and not included in this method’s response. The value returned by getFeeForMessage is the base fee only.

Common errors

  • Blockhash expired — value is null when the message contains an expired blockhash. Recreate the message with a fresh blockhash from getLatestBlockhash.
  • Invalid message — a malformed or incorrectly encoded message returns a parse error.

Performance

getFeeForMessage is lightweight — it counts the signatures in the message and multiplies by the fee per signature. There is no on-chain lookup beyond blockhash validation. On the current fee schedule, you can calculate the fee yourself: count the required signatures and multiply by 5,000 lamports.

FAQ

What is the current base fee per transaction? The standard base fee is 5,000 lamports (0.000005 SOL) per signature. A typical single-signer transaction costs 5,000 lamports.

Does this include priority fees? No. getFeeForMessage returns only the base fee. Priority fees set via setComputeUnitPrice are separate and depend on the compute unit price you specify and the compute units consumed.

Why does the method return null? The blockhash in the message has expired. Solana blockhashes are valid for approximately 60-90 seconds (roughly 150 slots). Generate a fresh blockhash with getLatestBlockhash and rebuild the message.

Can I estimate fees without building a full message? Yes. If you know the number of signers, multiply by 5,000 lamports. A single-signer transaction always costs 5,000 lamports in base fees, regardless of the number of instructions.

How do priority fees work? Add a setComputeUnitPrice instruction to your transaction. The total priority fee is computeUnitsConsumed * computeUnitPrice / 1,000,000. This is paid on top of the base fee.

Parameters

ParameterTypeRequiredDescriptionDefault
messagestringYesBase-64 encoded transaction message.—
commitmentstringNoCommitment level: processed, confirmed, or finalized.finalized
minContextSlotnumberNoMinimum slot at which the request can be evaluated.—

Updated: