If you’ve ever used the Ethereum blockchain, you definitely might have heard of Ethereum gas. Well, if you haven't heard of it, you’re not alone. No one would have just known about Ethereum Gas on sight, right? They would have googled it. That's why you’re here right? To learn. So now, before we look at what gas is, let's first learn about Ethereum, the EVM (Ethereum Virtual Machine) and smart contracts.
Table of Contents
- What is Ethereum?
- What is a EVM
- Smart contracts and what they are
- Denominations of Ethereum
- What is Ethereum Gas?
- Ethereum gas limit
- What happens if there is too little gas?
- How are the gas fees set?
- Cancelling stuck Ethereum transactions
- Gas price
- Block Gas Limit
What is Ethereum?
With its own smart contract functionality, Ethereum allows you to move money directly without providing all your personal details. All with just a small fee. Ethereum can be used for decentralized finance, the exchange as well as creation of NFTs (non-fungible tokens) and also has been utilized for many initial coin offerings. It can also be used for Decentralized Autonomous Organisations (DAOs).
Ethereum 2.0, also called Eth2 is the next upgrade on the Ethereum blockchain. Ethereum 2 is said to be released in phases with it’s first one starting in 2020. This next level update plans to make Ethereum more scalable, more secure, and more sustainable. The Beacon Chain is already live, the Shard chains are planned to release in 2021 and the docking is planned for 2022. So by the end of all the upgrades, the Beacon chain wll include Shard 1, Shard 2, Shard 3 … and the Mainnet. One of the key updates in ETH2 is the introduction of staking.
What is a EVM?
EVM stands for Ethereum Virtual Machine and is a software platform. It is based on blockchain and used to make DApps, Decentralized Apps. DApps creation with EVM, the Ethereum Virtual Machine, does not require hardware that is really powerful.
Ethereum functions on opcodes, operation code. Opcodes is the part of the code that specifies what operation the EVM has to do. It is a set of instructions. As programming languages used to develop smart contracts, like Solidity, Vyper, Serpent, etc, cannot be executed by the EVM, opcodes are compiled so that the machine can understand them. The EVM has 140 opcodes! This makes the EVM Turing-Complete. 140 opcodes is a lot as the maximum opcodes is 256. This is because an opcode is 1 byte and 162 is 256.
The EVM is isolated, i.e. they do not use any other process in your computer. To destruct the EVM account, you have to use the Solidity command selfdestruct.
What is a smart contract
Just by reading the word smart contract, we can’t assume that it is smart or is a contract. It actually has a very different meaning. To quicken up the transactions made, a set of rules are created and they are stored on the blockchain.
These set of rules get executed automatically and don’t need anyone to imply them on blockchain. These set of rules that run by themselves when a transaction is made are called smart contracts. A smart contract can define conditions for corporate bond transfers, include terms for travel insurance to be paid and much more. Smart contracts are made by their own programming languages.
Examples of smart contract languages: Bitcoin aims to create its smart contract language called Sapio (under development). Bitcoin has limitations in running smart contract applications. On the other hand, Cardano (ADA) also aims to create and include its own smart contract via a platform called Plutus. The Platform, Plutus, is the smart contract platform of the Cardano blockchain. This smart contract will be deployed in the Goguen update. Unlike Bitcoin, Cardano does not have any limitations.
A liquidity pool is like a group of secured funds/assets in a smart contract. They are used to facilitate exchanges, lending etc and have many more purposes.
Denominations of Ethereum
There are many denominations of Ether, the smallest being wei. Here are the ‘orders of magnitude’ of Ether.
- Wei – 0.000000000000000001 ETH
- Kwei – 0.000000000000001 ETH
- Mwei – 0.000000000001 ETH
- Gwei – 0.000000001 ETH
- Microether – 0.000001 ETH
- Milliether- 0.001 ETH
- Ether- 1 ETH
- Kether- 1,000 ETH
- Gether – 1,000,000 ETH
- Tether- 1,000,000,000 ETH
What is Ethereum Gas?
On the Ethereum blockchain, Gas is literally like the fuel that processes transactions and smart contracts. Precisely, gas refers to the fee that the user pays in order to process a transaction. Just as much as a car needs fuel to run, the Ethereum platform needs gas in order to operate. So, Gas is a unit, measured in gwei (a small fraction of the crypto ETH also known as nanoether), that measures the amount of computational effort put in to carry out certain operations on the ethereum network.
The exact price of Gas is not specific as miners set the price based on supply and demand for the miners network such as the computational power required to process self-executable smart contracts. One important thing to remember is that every single operation that takes part in Ethereum requires an amount of gas in some ways. Due to this, miners get paid an amount in Ether equivalent to the amount of gas required to complete the operation.
Here’s an instance of gas being used. Nearly all of the smart contracts that run in the EVM (Ethereum Virtual Machine) are coded with Solidity. Solidity is a statically-typed programming language designed for developing smart contracts that run on the Ethereum Virtual Machine. Ethereum plans on moving to Viper but let’s just leave it for now.
What is Gas limit
In simple terms, the maximum amount of gas that the sender is willing to pay for the transaction is known as the gas limit. This gas amount must be specified by the sender before the transaction.
The transaction processing cost was brought to the blockchain to make it easier to calculate the resources used when executing a transaction. The unit of gas necessary for a transaction is already predefined. The predefined unit is calculated by the amount of computational work done to allow it to execute. If more computational work is done to process transactions and smart contracts, then a higher gas limit will be displayed.
This gas limit is used to ensure that the transaction is executed. Some basic computations require a predetermined number of Gas, that’s why the Ethereum yellow paper states that every transaction should have a standard gas limit of 21,000. That is why in most places, you would see 21,000 as the gas limit by default.
We can also determine the gas costs with simple multiplication. So, for example, let’s assume that the gas price is 33 (gas price) gwei when the transaction is being sent and the standard gas limit is 21,000 (gas limit). Also, one gwei is 0.000000001 ETH (gwei denomination). So all we have to do to find the gas cost is multiply the gas limit, gas price and the gwei denomination. That is: 21,000 (gas limit) x 33 (gas price) x 0.000000001 (gwei denomination). If you multiply all this together, you get a transaction fee of 0.264 ETH which is today’s worth is $726. So that’s it, now you know how to calculate gas fees. So that’s all gas limit is. To keep it simple and easy, you can compare the gas limit to the car fuel tank.
What happens if there is too little gas?
So, now that you know about gas, you might be wondering what happens if there is too little gas. So, if there is too little gas, no changes happen at first. At the start, your transaction will be initially executed by the miners just like all the others. Then, once the gas runs out, the blockchain records the transaction as “Failed” and the miners stop performing their work.
Due to the insufficient gas, nothing will happen to your ETH, it will still be in your wallet. However, you can not get your gas back as it will be kept with the miners for their work as fees. So the only thing that happens if you have too less gas is that your ETH will not be affected, however, your gas will be lost.
How are the gas fees set?
One thing to understand is that the exact price of Gas is not specific. It keeps changing. This means that the gas price can differ wildly from a block to another. Three huge misunderstandings that people make about setting the gas fees are:
- Gas prices are set by the miners
- The gas price gets changed with a community-vote
- The developers set the gas price
All these are wrong, infact, the gas price is not set by the miners, the developers or the community. The price is set by the – wait for it- users. Yep, that’s correct. When users send transactions, they also tell them their requested gas price. When the miners want to mine a block, he chooses the transaction with the requested gas price. So, in simple terms, the user sends a transaction along with a gas price. When a miner looks at it, he decides if he wants to pick the transaction or not. So, mostly, transactions sent at higher gas prices have more chances to be processed as most of the miners will accept it.
Currently ETH Gas Station recommends that the average gas price in gwei for a Trader< ASAP should be 63. The Fast< 2m gwei price should also be 63 and finally the Standard< 5m gwei price should be 39. This recommended price intends to be both cheap and successful. This price will also be accepted by the top 50 miners who accounted for at least 50% of the blocks safely and promptly. This is the lowest gas price that is accepted by all top miners (from the previous two days, can change).
Cancelling stuck Ethereum transactions
Yes, it can happen sometimes. A few times, Ethereum transactions get stuck in the platform’s ongoing pool. This happens because miners look out for high fee transactions, so when they spot one, they head on to that and leave your transaction in a long queue.
Once that happens, you’re not all lost, you can still cancel that transaction and try again (if you want) with a faster gas fee. So, here are the steps:
Step 2: Here, you will see a Ethereum Blockchain Explorer screen appear. Place your Txn hash (Transaction hash) into the search bar at the top.
Step 3: When the screen appears, click on the “Click to see more” button.
Step 4: In this screen, your nonce will appear. A nonce is the number of the transaction of the sender’s address. Make sure that you remember this number.
Step 5: Prepare a new ETH transaction in your wallet to sort things out.
Step 6: Activate the “ability to customize your nonce” which you can find in your wallet’s settings. This has to be done in order to enter the nonce sometimes.
Step 7: Go to the tab at the top, called “Advanced” and give the same nonce that you found in your stuck Tx.
Step 8: Now, create a new transaction. This transaction should have a “Fast” gas fee.
Step 9: Now, apparently, your original transaction will be unstuck once this confirms.
The price per unit of Gas is represented by a denomination of ETH. This denomination is called gwei. One gwei is 0.000000001 ETH just in the same way that 1 cent is equal to 0.01 dollar. This means that 1 ether = 1,000,000,000 gwei (10^9). Currently the average gas price is 47 gwei, that is $2.81.
When transactions are sent, the gas price is also sent along them (which we looked at in the gas limit paragraph). The price that you pay determines how quickly your transaction will be mined. If you give out a high gas price the higher will be the chances that the transaction will be included in the next block quickly since this is what incentivizes miners to work on it. Here’s what determines how quickly your transaction will be mined:
- 20 Gwei gas price will get you done within the next few blocks.
- 40 or more Gwei gas price has a lot of chance that your transaction will be done in the next block.
Block Gas Limit
Ethereum has a block gas limit because it does not have a fixed block size like Bitcoin (which has a block size of 1 mb). So, in Ethereum, instead of a fixed block limit, each block is bound by the units of gas. Block gas limits are the maximum amount of gas allowed in a block which is set by the network and the miners collectively.
This is done to determine how many transactions can fit into a single block. At the time of this writing, the average Ethereum block size is somewhere between 40 to 50 kb in size. Currently (at the time of writing), miners are handling blocks with a block gas limit of around 14,946,000 gas on average. One important thing that ensures that the blocks aren’t large is that the total amount of gas in all the transactions from the block must be less than the block gas limit. If the blocks are too large, then the nodes would stop bit by bit as it won’t be able to keep up with the network.
At first, in block 0, the block gas limit was set to 5,000. From then, any miner who wants to mine a new block can alter the gas limit by up to about 0.1%. So, in short, miners on the network decide what the block gas limit is. Miners have the chance to change this but some just leave it.
Disclaimer: Digital Wallets News does not recommend that any cryptocurrency should be bought, sold, or held by you. Do conduct your own due diligence and consult your financial advisor before making any investment decisions.