Gas is the fee for the network to process your transaction or execute a smart contract. You encounter such a fee every time you send cryptocurrency, trade on a DEX (decentralized exchange), or use a dApp (decentralized application). Understanding how gas works is worthwhile at least to avoid overpaying and encountering unpleasant surprises out of the blue.
KEY CONCEPTS
Gas measures the computational work the network performs for your operation. Essentially, it's the price for using the blockchain's shared resources. This mechanism encourages economical resource use and discourages flooding the network with spam transactions, as each one costs something.
To speak the same language going forward, here are the main terms:
- Gas limit: the maximum amount of gas you are willing to spend on a transaction.
- Gas price: how much cryptocurrency you pay for one unit of gas.
- Transaction fee: the total cost, which equals the gas used multiplied by the gas price.
- Computational effort: how much gas the transaction or smart contract actually consumed.
- Network congestion: high demand for block space, which pushes the gas price up.
- Miner/validator reward: payment to network operators for processing transactions.
HOW IT WORKS
Suppose you are sending 0.05 ETH from wallet A to wallet B on the Ethereum network. When initiating the transaction, you set two parameters: gas limit and gas price. The network estimates how many computational resources your operation will require, and this work is measured in "gas units."
The final fee is obtained by simple multiplication: used gas units multiplied by your chosen gas price. Let's say the transaction requires 21,000 gas units, and you set the gas price at 50 Gwei. Then the fee will be 0.00105 ETH (21,000 × 50 Gwei). This money goes to the validators as payment for processing and verifying your transaction.
The gas limit acts as a safeguard. If the transaction consumes less gas than the limit set, the remainder is returned to you. However, if more gas is needed than the limit, the transaction aborts with an error, but the gas spent up to that point is not refunded. This is how the network insures itself against operations that consume resources uncontrollably.
USE CASES
Most often, you pay gas when simply sending coins from your wallet to another address, whether it's Bitcoin, Ether, or stablecoins. The fee is the reason why validators agree to accept and confirm your transaction.
Interacting with decentralized applications is also not free. Swapping tokens on a DEX, adding liquidity, minting an NFT, each of these actions loads the blockchain with computations, meaning it incurs a gas fee.
Gas can even be spent on seemingly minor steps, such as granting a smart contract permission to manage your token before an exchange. Understanding these costs helps in planning activity and choosing moments when the network is less busy and fees are lower.
A good illustration of how much the cost can vary is comparing a Layer 1 (L1) network with Layer 2 (L2) solutions, which process transactions off the main chain and then record the result on it.
| Where the transaction occurs | Gas Fee |
|---|---|
| Ethereum Mainnet (L1) | noticeably higher, especially during congestion |
| L2 Solutions (Polygon, Arbitrum) | significantly lower due to off-chain processing |
FREQUENTLY ASKED QUESTIONS
The gas price is not fixed; it fluctuates with demand. When many users try to conduct transactions simultaneously, the gas price jumps. The logic is the same as with dynamic pricing for taxi services: the more people want a ride, the more expensive it gets.
The fee structure varies among different blockchains. Bitcoin charges based on the transaction data size, while Ethereum calculates based on gas. Second-layer solutions like Polygon or Arbitrum offer significantly cheaper gas because they process transactions off the main chain and only record the final result on it.
The fee for a failed transaction cannot be refunded, but reducing the risk of failure is quite possible. Often, setting a gas limit with a buffer is enough to ensure the operation has sufficient resources to complete. And to catch moments with low prices, it's useful to monitor gas trackers.