BR Academy
0%
Transactions and Fees·Lesson 15 of 25·12 min

Gas, Fees, and Mempool

The Concept

Every block has a limited amount of space — a maximum number of transactions (or, more precisely, a maximum amount of computational work) it can include. That scarcity is the entire reason fees exist: when more people want their transaction included than can fit in the next block, fees become the mechanism that decides whose transaction gets priority. It works exactly like an auction — block producers are economically motivated to include the highest-paying transactions first, since the fee is their direct compensation for the work and resources of producing the block.

Gas is the unit that measures how much computational effort a transaction requires. A simple transfer of funds from one address to another costs a small, fixed amount of gas. A transaction that interacts with a smart contract — swapping tokens, minting an NFT, depositing into a lending protocol (Module 6) — requires the network to execute more computational steps, so it costs more gas. The total fee you pay is a function of two numbers: the gas price (what you're bidding per unit, which fluctuates with demand) multiplied by the gas used (how much computational work your specific transaction actually requires).

This is why fees aren't a fixed sticker price — they move with real-time demand for block space, the same way a rideshare's surge pricing moves with demand for cars. During quiet periods, the mempool (the pending-transaction waiting room from the previous lesson) is thin, so even a low fee gets included in the next block or two. During a busy period — a popular NFT mint, a token launch, a market crash triggering mass selling — thousands of transactions compete for the same limited block space at once, and fees spike because everyone is bidding to be the block producer's priority pick.

Many modern chains split the fee into two parts to make this auction more predictable: a base fee that the protocol itself calculates and adjusts automatically block-to-block based on how full the previous block was, and a priority fee (or "tip") that you set yourself to bid your way ahead of other pending transactions during contention. The base fee is often burned — removed from circulation entirely rather than paid to the block producer — while the tip goes directly to whoever includes your transaction. This design means the "surge pricing" is partly automatic (the base fee rises and falls with the network's own recent congestion) and partly a lever you control directly (the tip), rather than one undifferentiated number.

It's also worth separating gas price from gas limit. The gas limit is a cap you (or your wallet, by default) set on a transaction — the most computational work you're willing to pay for. If a smart contract interaction runs out of gas mid-execution because the limit was set too low, the transaction fails, but the gas actually consumed up to that failure point is still spent and not refunded — another reason wallets estimate gas limits conservatively rather than guessing low to save money.

Worked Example

Compare two mempool snapshots on the same network:

  • Quiet Tuesday afternoon: the mempool holds a few thousand pending transactions. Average fee to get included in the next block: low. A simple transfer clears in under a minute for a few cents.
  • Popular NFT mint launch: tens of thousands of wallets simultaneously try to mint in the same few minutes. The mempool floods far beyond what the next several blocks can hold. Fees spike 10x or more, because the only way to guarantee inclusion in the very next block is to outbid everyone else also trying to get in.

Both snapshots are the exact same underlying mechanism — an auction for scarce block space — just at two different demand levels. Nothing about the protocol "changed" between the quiet day and the busy launch; only the number of competing bidders did.

Exercise

Given a hypothetical gas price of 30 gwei and a gas limit of 21,000 (a typical simple transfer), calculate the rough total fee (gas price × gas used). Then explain, in your own words, why a transaction that swaps one token for another through a smart contract would have a much higher gas-used number than a simple transfer — tying your answer back to "gas measures computational effort," not transaction size alone.

Recap

  • Fees exist because block space is limited and scarce, turning inclusion into a real-time auction; many chains split this into an automatic base fee plus a user-set priority tip.
  • Gas measures the computational effort a transaction requires; total fee is gas price times gas used, capped by a gas limit that, if too low, causes a failed transaction that still consumes the gas spent.
  • Fee spikes during busy periods (a popular mint, a market event) reflect more bidders for the same limited space, not a change in the protocol itself.

Resources