Skip to main content

Gas and Fees: The Pricing Mechanism for On-Chain Resources

You've already explored the complete journey of a transaction, and now it's time to dive into the economic engine that powers it all—Gas and fees. By understanding this, you'll gain insights into the cost structure of the blockchain world and learn how to interact with it more economically.


1.6 Gas and Fees: The Pricing Mechanism for On-Chain Resources​

Gas quantifies every step of computation, storage, and bandwidth on-chain into a single unit, priced in real-time using the native on-chain token (like ETH), forming the resource market and security budget of the blockchain.

Think of Ethereum as a global computer. You can run programs (smart contracts) on it, but its resources—computing power, storage space—are limited and valuable. Gas is the mechanism that prices these scarce resources, much like how we pay for electricity or gasoline.


Why is Gas Needed?​

  1. Prevent Abuse: If on-chain operations were free, anyone could easily cripple the network with a malicious infinite loop program or a flood of spam transactions. The Gas mechanism ensures that every computational action has a cost, preventing resource abuse.
  2. Granular Pricing: Different operations consume resources to varying degrees. A simple transfer might involve only a few additions, while a complex DeFi protocol interaction might require multiple storage reads and writes and complex calculations. Gas sets a clear "gas consumption" for each basic operation (Opcode), allowing precise measurement and charging of resource consumption.
  3. Incentivize Validators: Part of the fees paid by users is rewarded to the validators/miners who package transactions, incentivizing them to invest in hardware and funds to process transactions and maintain network security. This fee is a crucial economic budget for network security.

Two Layers of Meaning in Gas: Measurement and Pricing​

Understanding Gas involves breaking it down into two concepts:

  • Gas Unit (Measurement Unit): This is purely a measure of computational workload, unrelated to money. The protocol specifies how much Gas each operation consumes. For example, an addition (ADD) operation might consume 3 Gas, while a permanent data write on-chain (SSTORE) is very "expensive," potentially consuming 21,000 Gas.
  • Gas Price (Price): This is how much you're willing to pay in native tokens for each unit of Gas (usually priced in Gwei, i.e., $10^-9$ ETH on Ethereum). It is a floating price determined by market supply and demand.

Total Transaction Fee (Tx Fee) = Gas Used × Gas Price

The fiat cost you ultimately pay is the total transaction fee multiplied by the current market price of the native token.


Evolution of Ethereum's Fee Model​

Ethereum's fee mechanism is not static; it evolves continuously to pursue better efficiency and user experience.

  • Traditional Auction (Pre-London Upgrade): This is a simple "highest bidder wins" model. Users set their own gasPrice, and miners prioritize transactions with the highest bids. During network congestion, this can easily trigger "bidding wars," leading to soaring and unpredictable fees.
  • EIP-1559 (London Upgrade, 2021): This revolutionary reform introduced a more complex dual fee structure:
    • Base Fee: Automatically adjusted by the protocol based on the congestion of the previous block. If block usage exceeds 50%, the Base Fee rises; if below 50%, it falls. This part of the fee is burned directly, not paid to miners.
    • Priority Fee / Tip: A voluntary tip added by users, paid directly to the validator who packages the transaction, incentivizing them to prioritize your transaction.
  • EIP-4844 Blob Gas (Dencun Upgrade, March 13, 2024): This is a major upgrade tailored for Layer 2 Rollup solutions.
    • It introduces an independent, cheaper data channel (Blob) specifically for L2 to publish transaction data to L1. This data only needs to be temporarily available on-chain for about 18 days, rather than permanently stored. According to analyses like Medium, this move reduces L2 transaction costs by 10 to 100 times.
    • Blob Gas has its own independent pricing market, separate from the regular smart contract execution Gas market, avoiding competition between L2 data publishing needs and regular user transactions, thus stabilizing fees for both parties. (Smartvalor provides a detailed explanation).

Pricing Strategies of Other Public Chains​

  • Solana: The fee model considers compute units and the number of signatures. A notable feature is the local fee market, where only transactions interacting with a specific, high-demand smart contract will see increased fees, without affecting other applications on the network.
  • Bitcoin: The simplest model, where fees are only related to the size of the transaction data (in bytes). Due to its limited scripting system, the consumption of computational resources is far less important than storage and bandwidth.
  • Cosmos SDK Chains: Validators can set their own minimum Gas price (min_gas_price) they are willing to accept. Transaction fees must exceed the node's set threshold to be processed.

Where Do Network Fees Go?​

The fees you pay ultimately flow to several places, collectively supporting the entire ecosystem:

  1. Paid to Validators: In PoS chains, most fees (such as the priority fee in EIP-1559) are directly allocated to the nodes proposing and validating blocks, as a reward for their staking and ensuring network security.
  2. Burned: In Ethereum, the Base Fee from EIP-1559 is permanently burned. This reduces the total supply of ETH, indirectly creating deflationary pressure and value scarcity for all ETH holders.
  3. MEV (Maximal Extractable Value): In complex DeFi transactions, there are "implicit fees" from profiting by ordering transactions. These values are usually captured by professional "searchers" and block builders and shared with validators.

How Can Users Save Money?​

  • Avoid Peak Times: Use tools like Etherscan to observe the historical curve of the Base Fee and choose less busy times (such as late night or weekends) for transactions, which will be much cheaper.
  • Batch Execution: If you have multiple transfers or operations, use tools that support batch processing (like Disperse.app) to combine them into one transaction, saving a lot of fixed costs.
  • Move to Layer 2: This is the most effective way to save money. Cross-chain assets to Arbitrum, Optimism, and other Layer 2 networks, where single transaction fees are usually below $0.1, or even lower. You only need to pay a higher L1 fee once when you need to move funds back to the mainnet.
  • Make Use of EIP-1559: In most cases, setting maxPriorityFee to 1-2 Gwei and maxFeePerGas to twice the current baseFee is sufficient to ensure your transaction is confirmed in a reasonable time, while avoiding unnecessarily high prices.

Developer Optimization Guide​

  • Streamline Storage: SSTORE is the most expensive instruction. When designing contracts, follow the principle of "compute rather than store" whenever possible.
  • Use Event Logs: Emit non-core business logic data through the LOG instruction as events, which off-chain applications can index, costing much less than on-chain storage.
  • Code Reuse: Share bytecode through library or proxy contract patterns to significantly reduce contract deployment costs.
  • Utilize Gas Refunds: In Ethereum, deleting a used storage slot (SSTORE from a non-zero value to zero) can earn a partial Gas refund, though this refund has a cap.

🤔 Reader Exercises​

  1. Visit the Etherscan Gas Tracker page. Record the current L1 Base Fee and the average transaction fee of a mainstream L2 (like Arbitrum). Calculate how much it would cost in USD to perform a standard ERC20 token transfer on both L1 and L2.
  2. Use the online Solidity editor Remix to deploy a simple smart contract with one function for writing a number and another for reading it. Compare the Gas consumption of "writing" and "reading" operations to personally experience the cost differences between storage and computation.

📚 Further Reading​


This concludes the entire content of Chapter 1, "The Foundation of the Internet of Value." You've journeyed from the essence of value transfer, learning about consensus mechanisms, block structures, identity keys, transaction processes, and resource pricing. You now have the basic framework to understand how the blockchain world operates.

In the next chapter, we will open a new chapter: entering the specific world of crypto assets. The first section (2.1) will focus on the starting point of everything: "How to Properly Understand Bitcoin and Its Value."