What Are Gas Fees and Why Are They Important

What Are Gas Fees and Why Are They Important

Everything you need to know about Gas fees from A - Z

Favor Onuoha's photo
Favor Onuoha
·Jan 27, 2022·

15 min read

Play this article

Table of contents

Introduction

If you’re reading this, then you’ve probably come across the term “Gas.” You might think about the gas you use in your car, but this term is also used on the Ethereum blockchain.

In recent times, gas prices have been increasing outrageously, even going as far as hindering trades and purchases on the Ethereum blockchain.

But what is this "gas" thing, and why does it exist? Well… Let's find out!

Ethereum meme

Genesis

The Ethereum blockchain is the second most popular blockchain, right after Bitcoin. Though Ethereum and Bitcoin both solve the same problem, they do have some major differences.

Vitalik Buterin, the creator of Ethereum, created Ethereum in 2013. When Ethereum was launched in 2015, it launched as an executable blockchain that uses its own internal programming language called Solidity. Solidity creates programs known as Smart Contracts that enable entities to develop and scale decentralized applications on a blockchain.

Executable Blockchain?

Solidity is a high-level, contract-oriented, object-oriented programming language used for writing Smart Contracts.

Smart contracts meme

A Smart Contract is a program that exists on a blockchain and can be executed when predefined conditions are met.

In Ethereum’s Whitepaper, Vitalik laid out the problems faced by Bitcoin and how it had no real-world value other than just being stock for high-risk investments.

Vitalik’s main problem with Bitcoin was that Bitcoin didn't offer a platform that its users and developers could scale on and build efficient apps that used the power of the blockchain network.

The Bitcoin network is the largest blockchain protocol in the world, with 10s of thousands of miners all working together to achieve consensus and keep the network running. That means that there are currently 1000s of computers currently connected to the Bitcoin network.

Believe it or not, this huge computational power does nothing but confirm transactions and blocks on the blockchain via consensus to keep the Bitcoin network running.

Let’s look at some charts now, shall we?

energy consumption of bitcoin compared to other countries.png

If you take a close look at this chart, you’ll see one thing, and that is my countries' Nigeria and Ghana made it to the list 🥳🎉🎊 Yeah!!!! Let's pop some champagne and celebrate!!!

people celebrating at festival

Alright, just kidding, what you actually see is that Bitcoin consumes a hell of a lot of electricity yearly, even more than Nigeria and Ghana combined and multiplied by a factor of two.

One would have thought back then, "Wouldn't it be great if people could make apps that could use all of the network's computing power and still confirm transactions?"

This would have been a very common thought in the mind of blockchain developers at that time, but Vitalik Buterin changed the whole game.

In Bitcoins defense, it does offer some sort of Smart Contract functionalities, but Vitalik termed Bitcoin’s implementation of it as “weak”. This is because it offers some scripting capabilities that do not match up to the level of the Smart Contracts we see today.

When Ethereum launched with Smart Contracts, it solved the problems stated above by allowing programmers to write programs that can be executed on the blockchain, and could both read and write on the blockchain.

This amazing new invention would allow developers to build apps known as dApps that are secured, decentralized, and most importantly, trustless.

Smart Contracts also enabled developers to be able to build their own cryptocurrencies known as Tokens on top of the Ethereum blockchain. At the time of this writing, the ERC-20 Token Standard is the most popular token standard out there steadily followed by the NFT standards (ERC-721, ERC-1155, etc).

Because of the birth of Smart Contracts, Ethereum now has a unique stance in the world of blockchain and Web3. This global standing has kicked off a Crypto evolution which has since exploded in popularity, and has given ordinary people a platform to bring their bright ideas to life.

Web3 projects like Uniswap V3 and AAVE are great examples of what can be achieved with Smart Contracts. I guess one can say that Smart Contracts have ushered in the Big Bang Era of executable crypto. The evolution is just getting started!

The Evolution and Limitations

If you have heard about NFTs, ERC-20 Tokens, etc, you would know that these blockchain technologies didn't exist before Ethereum. All these cool technologies are possible courtesy of Smart Contracts.

NFT Projects like The Bored Apes Yacht Club and Cyberpunks NFT which rocked the Crypto world and made its creators millionaires, all have the works of Vitalik Buterin to thank for.

Ethereum has created a universe in which both NFT creators and consumers can build their own isolated utopias, live in virtual harmony, and generate tremendous profits.

However, there is a catch!

GAS RUNS EVERYTHING!!!!!!!!

elmo in hell meme

  • You want to mint an NFT, even for FREE, you’ve got to pay Gas fees.
  • You want to send some tokens worth literally $0, you’ve got to pay Gas fees.
  • You want to swap some tokens, guess what? “you’ve got to pay Gas fees?”, yes! You’ve got to pay freaking Gas fees.

If you’ve ever deposited some $eth into your wallet before or minted an NFT, you probably faced this same challenge. But why does everything run on Gas?

Genesis

Alright, so you're probably wondering, “Why is this titled Genesis? Is Gas biblical in any way?”

First of all, no! Gas is not biblical in any way!

If you thought that, you need help! And the kind of help that I am about to give you.

So, let me help you understand why we need gas for Ethereum. Let’s backtrack to the early days of the Ethereum network development.

When Ethereum was developed with Smart Contracts, a few concerns (to put it mildly) were raised.

For example, what if someone created a Smart Contract and left an infinite loop in it, or what if someone wrote a Smart Contract that was too computationally expensive with shitty code? Or what if someone was acting in bad faith and wanted to slow down the entire blockchain network?

Miners are people on the network who use their hardware to solve algorithms. They confirm transaction blocks that are then added to the blockchain. Miners are responsible for keeping the network secure and running.

When a miner confirms a block containing a Smart Contract, the Smart Contract is executed by the miner's hardware. If someone programmed their Smart Contract in bad faith or to run indefinitely, that code could actively slow down that miner's hardware.

If you combine this scenario with 100 same issues, it would be possible for a group people with bad intentions to deploy fraudulent Smart Contracts with the goal of bringing down miners on the Ethereum network, slowing it down.

These concerns could be a big problem that could befall the Ethereum network if caution was not taken.

The developers and Vitalik Buterin had to come up with a way to:

  • Stop code execution in the case of infinite loops.
  • Discourage developers from writing very expensive computational programs.
  • Discourage hackers from trying to destabilize the network.

Solving all these issues would make the network safe for everyone and keep the network running smoothly.

Gas solved this issue.

So… What is Gas?

Gas fees are rewards given to miners for picking up transactions from the mempool, adding them to a block, and verifying them. So, essentially, Gas fees are transaction fees

A mempool is where pending transactions are stored until miners pick them up.

There are 2 cases in which a user can be charged for Gas.

Case #1: Transactions

A transaction in Ethereum is when you send ether to a friend. However, Smart Contract interactions are not transactions!

In transactions, a user is charged based on how much he/she is willing to pay the miners, for his/her transaction to get processed.

Miners use a proof-of-work algorithm to keep the network secure. They confirm transactions and add them to the blockchain using their expensive computers, and in exchange, the Ethereum network rewards them with ether.

Proof-of-work algorithm is a consensus mechanism that many blockchains use to keep their networks safe from scams. Miners solve complicated algorithms to confirm transactions to add to the blockchain.

Miners are financially motivated to confirm transactions with higher transaction fees in the mempool. This is because increased transaction costs result in an increased commission for miners.

It's important to remember that Ethereum can only process 15 transactions per second. This means that transactions with lower fees will be left behind and pending longer than transactions with higher fees.

Transactions that are not getting picked up by miners can use a fee bumping method called replace-by-fee, which duplicates the transaction and sends it into the mempool but with a higher gas price.

If your transaction is pending and you use MetaMask, you’ll see a button on your pending transaction telling you to “Speed Up”. The “Speed up” button uses the replace-by-fee method behind the scenes, to get your transaction picked up by miners at a higher fee.

With that said, it's important to remember that when network traffic reduces, the gas charge falls as well and that after your transaction is validated, the miners keep both your transaction and gas fees.

Case #2: Smart Contract Interactions

In a Smart Contract, a user is charged based on how much the sender is willing to spend per computational execution of the Smart Contract code.

Every line of code you write in Solidity comes at a cost!

Remember when we mentioned that Gas lets Ethereum limit or protect itself from shitty code? Well, this is how Ethereum does it.

For example, if you wrote a Smart Contract that loops 10 times and mints a new Token each time it loops, for each loop, you’ll:

  • Pay Gas for minting the Token, which may have its own level of computational complexity.
  • Pay Gas for the loop itself.

Let's take this solidity code for example:

pragma solidity ^0.6.6;

contract Loops {

    address[] public users;

    constructor() public {

        users.push(msg.sender);
    }

    function addUsers(address[] memory usersList) public {

        for(uint index = 0; index < usersList.length; index++) {

            users.push(usersList[index]);
        }
    }

    function getUsers() internal view returns (address[] memory) {

        return users;
    }
}

In the figure above, every line of code affects the Gas price.

  • Every variable added requires some amount of Gas
  • Every function added requires some amount of Gas
  • The data type of the variables also requires some amount of Gas
  • The for loop you see in there will cost Gas.

If it cost 200 units of Gas at 200,000,000,000 Wei or 200 Gwei to add one user to my usersList array, then if I were to add 10 users to the usersList, then it would cost 10 X 200 Gwei 200 units = 400,000 Gwei to be able to successfully add 10 users to our array.

Let’s say, for example, we set our gas limit to 100 units instead of 200 units. If we tried to add 10 users to our list, the loop would run, but it would throw an error because the gas supplied could not complete the entire operation.

This error is called an Out of Gas Error, and mainly happens when the Gas you supply to your contract interaction runs out mid-contract execution.

Out of gas error screenshot

The same would apply for deploying the Smart Contract; every line of code influences the Gas price in one way or another.

Before I continue, you're probably wondering, what are “Wei” and “units”?

Wei: Unit of Measurement?

So, what is this Wei thing and why does it exist?

Wei

Wei, simply put, is the smallest denomination of ether!

Wei was named after the Computer Programmer Wei Dai, who created b-money and was one of the first of 2 people contracted Satoshi Nakamoto, the creator of Bitcoin.

Gas fees are actually paid in ether and the Gas prices, are measured in GWei which is like Wei but a ‘Giga’ version of it.

Basically, 1 Gwei = 1,000,000,000 Wei = 0.0000000001 ether

Gas prices are influenced by the miners on the Ethereum network

Gas Prices

As mentioned earlier, you pay gas fees based on how much you're willing to pay for your transaction to be processed quickly and successfully.

This amount you’re willing to pay is known as the Gas Limit.

You can actually set a Gas Limit when making transactions. MetaMask lets you do this!

When conducting transactions, MetaMask or any other Dapp will recommend a secure Gas price for you. However, changing this is not recommended because you risk unintentionally causing your transaction to encounter a Out of Gas exception, resulting in a failed transaction.

When your transaction fails on the Ethereum network for whatsoever reason, you lose the money you spent on gas

It is also good to note that extra Gas spent on a transaction, will be sent back to the sender or owner of the transaction.

Basically, if you make a transaction that only requires 22,000 units of gas to be processed and you sent 40,000 units, 18,000 units of gas will be sent back to your wallet.

Screenshot of Gas limit settings in MetaMask

In the case of transactions, the minimum amount of gas required to process the transaction and pay is the miners is 21,000 units of gas.

For each unit of gas, you pay a Gas price.

For example, you’re sending 10 ETH to your friend Yosra.

Your total gas fee is calculated as:

Gas units (limit) * Gas price per unit

If today, the price of Gas on the Ethereum network is 50 Gwei, then you would have to pay 21,000 50 = 1,050,000 Gwei or *0.00105 ether.

So in total, you would be paying 10.00105 ETH, the miners get 0.00105 ETH and Yosra gets 10ETH.

Why Should I Care to Understand?

The year is 2021! It’s almost midnight at 11:31 PM and a young man in his late teens named David is about to take a nap.

He steadily walks by to the fridge to grab a glass of milk when suddenly, he hears a loud scream coming from his neighbor’s house. He runs over to his neighbor’s place hoping to check if his neighbor, the CEO of a major Crypto exchange is still in good shape. He knocks on the door but to no avail and then proceeds to kick down the door and finds his neighbor lying down almost half dead.

Shattered and disturbed at the sight of the CEO on the ground, David tries to revive the CEO but then stops and takes a look at the man’s phone, and on it, is a transaction from the Ethereum blockchain showing that his neighbor tried to move $100,000 in USDT on the blockchain which is totally fine.

All wasn’t still looking good until suddenly, the CEO grabbed David, brought his head closer, and sparingly whispered into his ears the words “Gas… It was the Gas… don’t repeat my mistakes, cough, goodbye”.

Confused and in shock, David takes a look at the gas fee spent on the transaction and finds out that as the CEO tried to transfer $100,000 in USDT, he had mistakenly spent a whopping $28,000,000+ on gas fees. Let me write that in text for you to understand! Twenty-Eight Million Dollars!!!!! was spent on gas fees alone making the total transaction an insane $28,000,000+ or 7,676.6 ETH.

Before we move on, I would like to state for the record that this story didn’t exactly happen, but the part about someone making a transaction worth $28 Mill, is real, in fact here is proof of it on Ethescan.

If there's one thing this narrative has taught you, it's that gas prices do matter! The company that performed this transaction was fortunate in that the miner reimbursed more than 80% of the money lost.

The entity in question is Bitfinix, a crypto corporation you may have heard of if you've been around in the crypto space for a while.

If anyone other than a large crypto exchange company like Bitfinix had been in that circumstance, I'm sure it would have ended in tears!

That being said, if you want to participate in the Ethereum network, you must first grasp how Gas fees operate because losing money is not a fun sport!

End Game: Ethereum 2.0

Ethereum gas fees meme

The much-awaited upgrade to Ethereum being called Ethereum 2.0 or ETH 2.0 for short will see major changes to the network, some notable being:

  • Proof-of-Work (PoW) will be replaced with Proof of Stake (PoS)
  • Sidechains will be officially introduced
  • The number of transactions being confirmed per second will rise from 30 transactions/second to 100,000 transactions/second

Proof of Stake is a consensus method that requires users to stake their cryptocurrency as collateral to compete for network rewards.

But I know what you’re thinking, “Where’s the part that has to do with gas prices?”. I know, I know, I left that out but let's think about it this way in steps:

  • Miners need gas to choose which transactions they’ll process to maximize their gains.
  • Miners use the Proof-of-Work Algorithm, which puts strain on their hardware. Proof of Work will no longer exist on the network after the upgrade.
  • Meaning Miners will also not exist too after the upgrade.
  • This also means that there will be no more miners to dictate gas prices anymore. And gas prices will not even be needed to pay miners who won't even exist anymore.

This is great news for those who have been plagued by gas prices for years. We can now finally live in an Ethereum Utopia, where gas prices do not hinder our transactions and stop us from truly being free on the network… right??

Well.. wrong, Gas prices will still exist but since they will no longer be in demand, it's safe to assume that gas will only be crucial for Smart Contract interactions and deployments.

TL;DR

Gas fees can be a real pain in the ass, but they are also super important!

Understanding gas fees and how they work are crucial for having a better experience on the Ethereum network.

In this article, we learned about the early developmental stages of Ethereum, how it differed from Bitcoin, and what led to its development.

We then learned about Smart Contracts and how they ushered in a boom in crypto demand and daily use. It empowered more people to build crypto eccentric apps that are secured by the blockchain and are decentralized in nature.

Subsequently, we learned how Gas makes the network secure for all, how the correlation between gas prices and miners work, and how miners can influence the price of gas on the network.

Then, we learned what Gas actually is and how it works. We examined how Gas prices are calculated with respect to gas units.

Finally, we learned about the future of Ethereum and how the harsh effects of gas prices will be almost nearly eliminated when the ETH 2.0 upgrade comes into effect.

Conclusion

Thanks for reading and making it this far.

I hope you enjoyed this article! I also hope that this article has improved your understanding of Gas and how it operates on the Ethereum network. Hopefully, it has helped you understand and define your own user experience on the network in terms of gas prices.

Where do you go next?

We've got your back! If you want to learn more about Web3, NFTs, dApps and everything in between our web3 blog is a good place to start.

Cheers!

 
Share this