TL;DR: Just like you pay a wire or ACH fee when transferring money out of your bank account, you must pay a fee (called a network fee or gas fee) to send transactions or execute a smart contract on Ethereum. It is like paying a toll to use the Ethereum network.
What is gas?
You may think of filling up your car, or even what you ate earlier, when you hear the term gas. Yet the term has a special context in the world of crypto. Gas in crypto refers to the computational effort required to execute operations.
You must pay a gas fee in order to make a transaction or execute a smart contract on Ethereum. Regardless of the wallet you use, you will always need to pay for gas when executing transactions.
Need to send your mom some ETH? That transaction requires gas. Want to lend out your money via Compound? That transaction requires gas too. What about buying an NFT? You guessed it–gas. Gas is like a toll. If you want to use the highway, you have to pay the toll. The more duress a vehicle puts the road under, the higher the toll the driver must pay. Tolls are a lot higher for 18 wheelers than motorcycle drivers.
Similarly, the more complex the transaction on Ethereum, the higher the gas fee.
What is a gas limit?
Gas fees are denoted in Gwei, which is just .000000001 ETH. You can think of Gwei like cents, since 1 cent is .01 of a dollar. For every transaction you want to make, you must set what fee you are willing to pay for your transaction to be executed.
The maximum amount of gas you are willing to pay for in a particular transaction is called the gas limit. Additionally, you must input the gas price for each transaction as well. The gas limit x gas price = gas fee. You pay the gas fee when you submit a transaction.
Lucky for you, MetaMask calculates the approximate gas fee you should set for you based on how fast you want your transaction to be confirmed.
Where your gas fees go
You might be wondering “why will my transaction be confirmed if I set a higher gas fee?” An excellent question!
When you submit a transaction on Ethereum, you are competing with others who also want to submit a transaction. While you might be sending your mom some Ether, someone in India might be trading on Uniswap. Each person is trying to have their transaction executed at the same time. But, only so many transactions can be included in an Ethereum block, and there are only new blocks every roughly 13 seconds. In fact, each block contains only 12.5 million units of gas. This means everyone is competing against one another to have their transaction included in the next block. When demand is high, and supply is constrained since only so many transactions can be included in a block, price must increase.
But when you submit transactions, where do they before miners approve them? These transactions go to the mempool, short for “memory pool.” The mempool is where all the transactions that have been submitted -- but not yet verified -- live. In short, the mempool is the waiting queue for validation. Miners, who validate transactions before execution to make sure they aren’t malicious, pick the transactions that should be included in the next block from the mempool.
“So why would miners pick my transaction from the mempool before everyone else?” Because I will pay them more of course!
Miners select what transactions should be included in the next block based on how high the gas fee users set prior to submitting the transaction. The higher the gas fee, the higher chance a miner will be willing to include your transaction in the next block. This situation is where the competition comes in, since you compete with everyone else setting gas fees during that time frame for block space.
Why do transactions take so long?
Since all users compete against one another for block space, when you set your gas fee too low, miners will opt not to include your transaction in a block in the near future. Thus, your transaction takes so long because you did not set the gas fee high enough for your transaction to be included in a near future block. You will have to wait for the gas fees that other users are willing to pay to go down for your gas fee to be attractive to miners.
Series Disclaimer:This series article is intended for general guidance and information purposes only for beginners participating in cryptocurrencies and DeFi. The contents of this article are not to be construed as legal, business, investment, or tax advice. You should consult with your advisors for all legal, business, investment, and tax implications and advice. Consensys is not responsible for any lost funds. Please use your best judgment and practice due diligence before interacting with smart contracts.