services
Get a key

library / How to use Solana / HS0030

Transaction fee breakdown

One TypeScript file fetches a transaction, prints the total fee, the base fee from its signature count and the priority fee left over, and checks that number against the compute-unit limit and price in its instructions. It only reads.

By Carbium · Priority fees and compute · HS0030 · updated 2026-11-22

01

What the fee is made of

getTransaction returns meta.fee, the total lamports the payer was charged. That number is two parts added together. The base fee is 5,000 lamports for each signature on the transaction, plus 5,000 for each signature that an Ed25519, Secp256k1 or Secp256r1 precompile instruction verifies. The priority fee is whatever the sender asked for with two compute budget instructions: a compute-unit limit, and a compute-unit price in micro-lamports per compute unit.

The split is arithmetic on values you can read. The base fee is the billed signature count times 5,000. The priority fee is the total minus the base. The price and limit, decoded from the compute budget instructions, let you check the result: limit times price, divided by 1,000,000 and rounded up to a whole lamport, must equal that difference.

The runtime charges the limit that was requested, up to 1,400,000 units, whatever the transaction burned. A transaction that asks for 1,400,000 units and uses 60,000 pays for all 1,400,000. The burned count sits in meta.computeUnitsConsumed, and the gap between it and the limit is the cost of an oversized request. A transaction that landed and failed pays the same fee as one that succeeded.

02

The code

Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24, which strips the types on load. Pass a signature as the first argument. With no argument the file lists the newest signatures that mention the compute budget program, skips the failed ones and uses the first that getTransaction can still return.

main.ts
// HS0030 · Transaction fee breakdown// https://carbium.sh/library/howsolana/transaction-fee-breakdown// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport {  address,  createDefaultRpcTransport,  createSolanaRpcFromTransport,  getBase58Encoder,  signature,} from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) {  console.error("CARBIUM_KEY is not set.");  process.exit(1);}const client = createSolanaRpcFromTransport(  createDefaultRpcTransport({    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",    headers: { "x-api-key": key },  }),);const BUDGET = "ComputeBudget111111111111111111111111111111";// Ed25519, Secp256k1 and Secp256r1 precompiles: data byte 0 counts the signatures they verify.const VERIFIERS = new Set(["Ed25519SigVerify111111111111111111111111111", "KeccakSecp256k11111111111111111111111111111", "Secp256r1SigVerify1111111111111111111111111"]);const FEE_PER_SIGNATURE = BigInt(5000);const MAX_UNITS = BigInt(1_400_000);const base58 = getBase58Encoder();// Little-endian unsigned integer of `width` bytes starting at byte 1.function readUint(bytes: Uint8Array, width: number): bigint {  let out = BigInt(0);  for (let i = width; i >= 1; i--) out = out * BigInt(256) + BigInt(bytes[i] ?? 0);  return out;}async function explain(sig: string): Promise<string[] | undefined> {  const tx = await client    .getTransaction(signature(sig), { encoding: "json", commitment: "confirmed", maxSupportedTransactionVersion: 1 })    .send();  if (!tx || !tx.meta) return undefined;  let limit: bigint | undefined;  let price = BigInt(0);  let verified = 0;  const { accountKeys, instructions } = tx.transaction.message;  for (const ix of instructions) {    const program = accountKeys[ix.programIdIndex];    const data = Uint8Array.from(base58.encode(ix.data));    if (VERIFIERS.has(program)) verified += data[0] ?? 0;    if (program !== BUDGET) continue;    if (data[0] === 2) { const asked = readUint(data, 4); limit = asked < MAX_UNITS ? asked : MAX_UNITS; }    if (data[0] === 3) price = readUint(data, 8);  }  const count = tx.transaction.signatures.length + verified;  const base = BigInt(count) * FEE_PER_SIGNATURE;  const rows: Array<[string, string]> = [    ["signature", sig],    ["total fee", `${tx.meta.fee} lamports`],    ["base fee", `${base} lamports (${count} billed signature(s) x 5000)`],    ["priority fee", `${tx.meta.fee - base} lamports`],    ["price", `${price} micro-lamports/CU`],    ["limit", limit === undefined ? "unset" : String(limit)],  ];  if (limit !== undefined) {    const owed = (limit * price + BigInt(999_999)) / BigInt(1_000_000);    rows.push(["check", `${owed} lamports (limit x price / 1,000,000, rounded up)`]);  }  rows.push(["used", `${tx.meta.computeUnitsConsumed ?? "unknown"} compute units`]);  return rows.map(([label, value]) => label.padEnd(14) + value);}const given = process.argv[2];const candidates = given  ? [given]  : (await client.getSignaturesForAddress(address(BUDGET), { limit: 10 }).send()).flatMap((row) => (row.err === null ? [row.signature] : []));for (const sig of candidates) {  try {    const out = await explain(sig);    if (out) {      console.log(out.join("\n"));      process.exit(0);    }    console.log(`${sig} not returned, trying the next`);  } catch (e) {    console.log(`${sig} failed: ${e instanceof Error ? e.message : String(e)}`);  }}console.error("No transaction could be read.");process.exit(1);

run: node main.ts [signature]

The compute budget program is a good place to look for a sample, because every transaction that sets a price or a limit names it. getSignaturesForAddress returns signatures newest first. Each candidate goes through getTransaction with commitment: "confirmed", the value @solana/kit fills in when a call leaves it out, written out here so the read is explicit. maxSupportedTransactionVersion: 1 lets a v1 transaction come back as data.

In the json encoding the instruction data is base58, and getBase58Encoder turns it into bytes. For the compute budget program, byte 0 is the instruction kind. Kind 2 sets the limit as a little-endian u32, and kind 3 sets the price as a little-endian u64. A request above 1,400,000 is billed at 1,400,000, so the file keeps the smaller of the decoded limit and that cap. The price stays a bigint, so the product of price and limit never rounds. For the three precompile programs, byte 0 is the number of signatures the instruction verifies, and the loop adds that number to the count on the transaction.

03

Reading the output

A run prints one line per value, all in lamports unless the line says otherwise.

LineWhere it comes fromMeaning
total feemeta.feeEverything the payer was charged.
base feebilled signatures times 5,000The fixed part, one charge per signature.
priority feetotal minus baseWhat the sender paid to be ordered ahead.
pricecompute budget instruction 3Micro-lamports per compute unit.
limitcompute budget instruction 2Compute units the sender requested, capped at 1,400,000.
checklimit times price, over 1,000,000, rounded upShould equal the priority fee.
usedmeta.computeUnitsConsumedUnits the transaction burned.

A worked case: a transaction with 2 signatures, a limit of 200,000 and a price of 5,000 micro-lamports. The base fee is 10,000 lamports. The priority fee is 200,000 times 5,000, divided by 1,000,000, which is 1,000 lamports. The total fee is 11,000, and the file prints a matching check.

$Plenty of transactions set no price at all. Their priority fee is 0 and the total equals the base fee, so a run on such a signature prints price 0 and, when a limit is set, a check of 0.
04

When the numbers differ

  • No limit instruction. The runtime then applies its default allotment per instruction, and the file prints the limit as unset and skips the check. The priority fee is still the total minus the base.
  • A signature verified by a precompile instruction. Each one is billed 5,000 lamports in the base fee. A run that skipped them would show price 0 beside a total above the signature count times 5,000, with the extra lamports sitting in the priority line.

To go from one transaction to a price you can use on your own sends, see Priority fee per compute unit, which samples recent slots for a price to send with.

05

On Carbium

The file makes two kinds of call to the one RPC endpoint: a getSignaturesForAddress page when no signature is given, and one getTransaction per candidate until a read returns. Each call costs 50 cells. The getTransaction rate is 0.24, 1.2, 5 and 25 req/s on Free, Dev, Business and Pro, so a loop over many signatures should pace itself to the per-plan rates.

Limits are per account, so every key of your account draws on one budget. See limits for how a burst is absorbed. When you page through an address's last 30 days with before, pace the reads of each page's transactions at the getTransaction rate, which is never above the getSignaturesForAddress rate on any plan.

For a service that explains transactions to users, Transaction explainer builds on this read and decodes the instructions as well.

06

Where it ends

getSignaturesForAddress on Carbium reaches back 30 days at most, from its own address index. Its pages can reach below the validator's ledger floor, so getTransaction can answer null for an older signature the list returns. The file handles a null by trying the next candidate. An empty page past 30 days marks the age limit of the index, and the address may have older transactions.

The numbers describe one landed transaction. They tell you what a sender paid at that moment and are no quote for a new send. Contention on a busy writable account can make the same price too low a minute later.

The file reads price and limit from compute budget instructions and counts verified signatures from the three precompile programs. Mainnet carries v1 transactions, and a read without maxSupportedTransactionVersion answers -32015 for them; the cause and fix are in Transaction version error -32015.

Lamports are the unit throughout. Turning them into dollars needs a price from you, and the file does not make one.

07

When it goes wrong

what goes wrongwhat to do
Error -32015 on getTransaction.The call left out maxSupportedTransactionVersion, or set it to 0, for a v1 transaction. Pass maxSupportedTransactionVersion: 1 with an encoding.
Every candidate prints not returned.The newest signatures are usually readable, so check the key and the endpoint first. A signature older than the validator's ledger can answer null even when getSignaturesForAddress lists it. Pass a recent signature as the first argument.
Price prints 0 but the total is above the signature count times 5,000.Each signature checked by an Ed25519, Secp256k1 or Secp256r1 precompile instruction adds 5,000 lamports to the base fee. The file adds them from data byte 0 of those instructions, so compare the count on the base fee line with the signatures you expect.
The check differs from the priority fee.Look for a requested limit above 1,400,000, which the runtime bills at 1,400,000. The file caps the limit the same way, so a copy of this logic without the cap shows a check above the priority fee.
CARBIUM_KEY is not set.Export CARBIUM_KEY in the shell that runs node main.ts.
08

Questions

Does `meta.fee` include the priority fee?

Yes. It is the total charged: the base fee for every billed signature plus the priority fee. Subtract the billed signature count times 5,000 to get the priority part, where billed signatures are the transaction's own plus those its precompile instructions verify.

Why does a failed transaction still show a fee?

Once a transaction lands, the fee is charged whether its instructions succeed or not. Failed ones show the same split as any other.

Is the priority fee based on the compute units used?

No. It follows the limit the sender requested, so an oversized limit costs real lamports. Compare the limit with meta.computeUnitsConsumed to see how much of it went unused.

Can I read the fee without the instruction decoding?

Yes for a transaction with no precompile instruction: meta.fee and the signature count give total, base and priority. The decoding adds the price and limit, which let you verify the split, and the count of verified signatures.