---
id: HS0015
title: "Priority fee per compute unit"
url: https://carbium.sh/library/howsolana/priority-fee-per-compute-unit
collection: How to use Solana
category: Priority fees and compute
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Priority fee per compute unit

One TypeScript file samples recent prioritization fees for the accounts your transaction writes, prints percentile prices in micro-lamports per compute unit, and converts each into lamports for your compute-unit limit. It only reads: no keypair, no signature, no transaction.

## What the number is

A Solana transaction pays a base fee of 5,000 lamports per signature. It can also pay a priority fee, which the leader uses to order transactions that compete for the same accounts. The priority fee comes from two compute budget settings: a compute-unit limit and a compute-unit price. The price is quoted in micro-lamports per compute unit, and 1,000,000 micro-lamports make one lamport. "What price per compute unit" therefore asks for one integer to put in the `SetComputeUnitPrice` instruction.

The node keeps a short record that answers it. `getRecentPrioritizationFees` returns one entry per recent slot, about the last 150, each with a `slot` and a `prioritizationFee` in micro-lamports per compute unit. At about 200 ms a slot, that window spans about 30 seconds. Pass the accounts your transaction writes to and the entries reflect a fee to land a transaction that locks all of them as writable. Pass none and they describe the block as a whole.

Contention happens per writable account. A transfer between two quiet wallets competes with almost nothing, while a swap through a busy pool competes with every other swap on that pool. The file takes the accounts as arguments and samples the same set your transaction will lock.

## 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. The first argument is your compute-unit limit and defaults to 200,000. Every argument after it is a writable account.

`main.ts` (run: `node main.ts [compute-unit-limit] [writable-account ...]`)

```ts
// HS0015 · Priority fee per compute unit
// https://carbium.sh/library/howsolana/priority-fee-per-compute-unit
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
} from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),
);

// Usage: node main.ts [compute-unit-limit] [writable-account ...]
const [limitArg = "200000", ...accountArgs] = process.argv.slice(2);
const limit = BigInt(limitArg);
const accounts = accountArgs.map((a) => address(a));

// One entry per recent slot, in micro-lamports per compute unit. No commitment parameter.
const rows = await rpc.getRecentPrioritizationFees(accounts).send();
if (rows.length === 0) {
  console.error("The node returned no recent slots.");
  process.exit(1);
}
const prices: bigint[] = rows
  .map((r) => r.prioritizationFee)
  .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
const slots = rows.map((r) => r.slot);
const first = slots.reduce((a, b) => (a < b ? a : b));
const last = slots.reduce((a, b) => (a > b ? a : b));

const MICRO = BigInt(1_000_000);
const at = (p: number) => prices[Math.min(prices.length - 1, Math.floor((prices.length * p) / 100))];
// The runtime charges limit x price / 1,000,000 and rounds up to a whole lamport.
const lamports = (price: bigint) => (limit * price + (MICRO - BigInt(1))) / MICRO;

console.log(`${rows.length} slots, ${first} to ${last}, ${accounts.length} writable account(s) named`);
console.log(`compute-unit limit ${limit}`);
for (const [name, p] of [["p50", 50], ["p75", 75], ["p90", 90], ["max", 100]] as const) {
  const price = at(p);
  console.log(`${name.padEnd(4)} ${String(price).padStart(10)} micro-lamports/CU  ${lamports(price)} lamports`);
}
console.log("The 5000 lamport base fee per signature is charged on top.");
```

The `rpc` object is created once and reused for every call, and it sends them to the Carbium [RPC endpoint](https://carbium.sh/docs#endpoints). The node answers from the slots it recorded recently.

Prices stay `bigint` all the way through, because a price times a limit of 1,400,000 gets large fast and a float would round it. Each percentile is a plain index into the sorted prices. The lamport conversion rounds up, as the runtime does when it charges the fee.

## Reading the output

A run prints one line per percentile, taken across the slots in the window.

| Line | Meaning | Use it for |
|---|---|---|
| p50 | Half of the sampled slots had a floor at or below this price. | A transaction that can wait a few slots. |
| p75 | Three quarters of the slots had a floor at or below it. | A default for most sends. |
| p90 | Nine in ten slots had a floor at or below it. | A transaction you want in quickly. |
| max | The highest floor in the window. | A ceiling for a retry, and a sign of a spike. |

> Each entry is a floor for its slot: roughly the smallest fee a landed transaction paid there, among those that write the accounts you named. It tells you what has been enough to land, so a long run of zeros is normal on accounts nobody competes for.

Read the percentiles as a spread and watch the max. When p50 sits near zero and max is far above it, the account has bursts, and a price at p90 pays for the bursts you would otherwise miss.

## From price to fee

The priority fee is the limit times the price, divided by 1,000,000 and rounded up to a whole lamport. The runtime charges on the limit you request, whatever the transaction burns, so an oversized limit costs real lamports.

| Limit (CU) | Price (micro-lamports per CU) | Priority fee (lamports) |
|---|---|---|
| 200,000 | 1,000 | 200 |
| 200,000 | 5,000 | 1,000 |
| 1,400,000 | 5,000 | 7,000 |

The 5,000 lamport base fee per signature is charged on top. To set the limit, simulate the transaction, read `unitsConsumed` from the result and add a margin of your own. A price without a limit applies to the default allotment of 200,000 compute units per instruction, so set both. In a built transaction the two settings are the instructions `getSetComputeUnitLimitInstruction` and `getSetComputeUnitPriceInstruction` from `@solana-program/compute-budget`. Put them first in the message.

## On Carbium

[Limits](https://carbium.sh/docs#limits) are per account, so every key of your account draws on one budget. Sample once per transaction you send, or on a timer, and keep the result in memory for all your senders.

A JSON-RPC call can be a single call or a [batch](https://carbium.sh/docs#rpc) of up to 100. To price several account sets at once, POST an array of `getRecentPrioritizationFees` calls with a raw `fetch`, because `@solana/kit` has no batch call.

`-32601` means method not found: do not retry it. Check the spelling of the method name first, and read the other [error codes](https://carbium.sh/docs#errors) before you build retries around them.

## Where it ends

The percentiles describe the last 150 or so slots. They cannot see the next block. A burst that starts after your sample, such as a popular mint hitting the same account, raises the price needed while your estimate still reads quiet. For a send that matters, sample close to the send and retry with a higher percentile when it does not land.

Every entry is a floor, so a percentile of floors sits below what the most contended transactions paid. A price at p90 improves your odds without promising a slot.

An account that nothing wrote to in the window returns zeros. That means no competition was observed, and it says nothing about the next burst.

The call estimates the price only. The compute-unit limit comes from simulating your own transaction, and the 5,000 lamport base fee per signature is separate. Mainnet blocks carry no vote transactions, so every transaction in the window is a user transaction and nothing needs filtering out.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| Every percentile prints 0. | No landed transaction paid a fee on those accounts in the window, or you passed accounts your transaction only reads. Pass the accounts it writes to. If they are idle, zeros are the right answer for now. |
| Error -32601 method not found. | Check the spelling: `getRecentPrioritizationFees`, plural, camel case. A method that Carbium does not serve keeps answering -32601, so do not retry it. |
| HTTP 429 with a retry-after hint. | Wait the number of seconds in the header and try once more. If it repeats, sample less often and share one result across your senders. |
| The fee paid is higher than the estimate. | The fee follows the limit you set, whatever the transaction used. Simulate, read `unitsConsumed`, and set the limit close to it. |
| `SyntaxError: Cannot convert 200k to a BigInt`. | The limit argument must be digits only, such as `200000`. |

## Questions

### Is the price in lamports?

It is in micro-lamports per compute unit. 1,000,000 micro-lamports make 1 lamport, and the fee is the limit times the price divided by 1,000,000, rounded up.

### Which percentile should I start with?

p75 for ordinary sends and p90 when the transaction must land soon. On a retry, move up one percentile.

### Do I need a private key?

No. The call reads recent slots. The Carbium key only identifies your account to the RPC.

### How often should I refresh the sample?

The window holds about 30 seconds of slots, so a sample from the last few seconds is current. Sample at send time or keep one result in memory for all senders.

## Related

- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
