Transaction fees and compute units
Suggest an editA Solana transaction pays for two separate things. It pays a small fixed amount for the right to land in a block at all, and an optional extra amount for the leader to schedule it ahead of competing transactions. The first is the base fee, the second is the priority fee.
A fixed fee cannot tell transactions apart
The base fee is five thousand lamports per signature. A transaction with one signer pays five thousand lamports total in base fees. A transaction with two signers, say a multisig, pays ten thousand. The amount doesn't change with the size or complexity of what the transaction does. It exists to cover the cost of signature verification, which every validator has to perform, and to put a floor under spam. Half of the base fee gets burned, removed from circulation permanently. The other half goes to the validator that produced the block.
Before priority fees existed, this was the only fee, and the leader had no way to tell transactions apart. At five thousand lamports each, flooding the network was cheap, and in September 2021 bots chasing a token launch flooded it until block production stopped for seventeen hours, as told in Where Solana came from. Important transactions had no way to bid for inclusion ahead of the bot traffic. Adding the priority fee gave users a tool to express urgency and gave validators a signal for which transactions to favor.
The priority fee is a bid for earlier scheduling
The priority fee is on top of the base fee and is yours to set. It is the way a transaction tells the leader "schedule me ahead of the others." When the network is busy and more transactions arrive than fit in a block, the leader's scheduler sorts the incoming traffic by how much priority fee each transaction is paying per unit of computation, and works through them from highest to lowest. The priority fee goes entirely to the validator, none of it is burned.
Both fees are paid up front, before the transaction runs. If the transaction fails, the network still keeps the fees and the state changes roll back.
The priority fee is charged on the compute unit limit
The value that determines the size of the priority fee is the compute unit, abbreviated CU. Every operation a Solana program performs costs a fixed number of compute units. Adding two integers, reading a byte from an account, calling another program, hashing some data, each one has a CU cost set by the runtime. The total CU consumption of your transaction is the sum across every operation it executes.
The CU limit is the cap your transaction declares for itself. It is the maximum number of compute units the runtime is allowed to spend on you before reverting the transaction with a "compute budget exceeded" error. Each transaction gets a default CU limit if you don't set one explicitly: 200,000 CU per instruction for programs you write (native Solana programs use a separate budget), up to a hard ceiling of 1,400,000 CU for the entire transaction.
The CU price is how many micro-lamports you are willing to pay per compute unit of that budget. A micro-lamport is one millionth of a lamport, so the formula divides by a million to turn it back into whole lamports: priority_fee = CU_price × CU_limit / 1,000,000.
The priority fee is computed from the CU limit, the cap you reserved, rather than from the CU usage, what the program actually spent. If you reserve 200,000 CU and your program only uses 60,000, you still pay priority fee on all 200,000. The leader treats the cap as the resource you locked up, since they had to plan for it being used. On Ethereum the gas you reserve and do not use is refunded, as the contracts and gas lesson describes.
The leader fills the block from the highest bid down
Picture three transactions arriving at the same leader in the same block. Alice's transaction is paying 5,000 micro-lamports per CU, Bob's is paying 100, and Carol's is paying zero. All three have the default 200,000 CU limit.
Alice's priority fee comes out to 5,000 × 200,000 / 1,000,000 = 1,000 lamports, Bob's to twenty lamports, and Carol's to zero. The leader's scheduler sorts incoming transactions by priority fee per CU, fills the block from the top of the sorted list, and stops when the block is full. Alice lands first, Bob second if there is room, Carol last or not at all depending on how much demand the leader is seeing.
Two transactions whose writable accounts do not overlap can run side by side, as the instructions and transactions lesson showed, but transactions that write to the same account run one after another. If thousands of transactions want to write to the same account, for example the pool of a token that just launched, they form a queue for that account, and the priority fee per CU decides the order in it. A transfer between two unrelated wallets writes to different accounts and does not wait in that queue. On Ethereum every transaction in a block pays the same base fee per unit of gas, and the protocol raises it when blocks are more than half full, so one busy contract raises the fee for unrelated transactions too.
Budget compute on every transaction
The Compute Budget program is what you use to set the CU limit and the CU price. It is a built-in Solana program with two instructions you will use: SetComputeUnitLimit to set the CU cap, and SetComputeUnitPrice to set the per-CU rate. You include them in your transaction alongside your real work, and the runtime reads them before execution to size your budget.
Set the CU limit too high and every transaction pays priority fee on compute units it never touches, which adds up across thousands of transactions and, worse, dilutes your effective bid per CU so the leader treats you as a lower priority than you thought. Set it too low and the transaction reverts mid-execution with a compute budget error, and you still pay the fee with no result. The right move is to simulate your transaction first, see how many CUs it actually consumes, add a margin of ten or twenty percent, and set the limit to that. Programs change as you develop them, and a margin that was right last month may be wrong this month. The price comes from looking at what the network is currently paying for prompt inclusion, which you fetch from your RPC provider or estimate from recent blocks.
When you write a program, you make its CU consumption a number you care about. Cheap programs cost less in priority fees per execution, which matters when users run them millions of times.