Ethereum Gas for Dummies

Ethereum Gas for Dummies

Exploring Gas, Gas Price and Gas Limit.

Subscribe to my newsletter and never miss my upcoming articles

What is a Gas in Ethereum?

Gas is a measure of how much computation resources are used up while processing a transaction on the Ethereum Virtual Machine. A high gas means your transaction is complex, takes more time and CPU. For each opcode operation, a gas is attached and different opcodes have different costs. Check the full list of gas costs for all opcode operations here. In reality, comparing the ethereum gas to the fuel of a car, for a long-distance journey you need more fuel to reach your destination on the other hand for shorter distances, just a little fuel gets consumed and most likely you'll still have more fuel left in your tank.

With that out of the way, let's talk about Gas cost, price and limit and how they all relate with one another.

Gas Cost

Also known as transaction cost can be described as the final amount of gas fee to be paid to the miner as an incentive. Transaction cost can be estimated using the formula

Transaction cost = gasUsed * gasPrice

where gasUsed is the summation of gas used as a result of different opcode operation performed in that transaction. For instance, a SHA3 cost 30 gas, if the current gasPrice is 25Gwei which is 0.0000000025Ether, multiplying both would give a transaction cost of 0.0000000075 Ether.

Gas Price

Gas prices are denoted in gwei, which itself is a denomination of ETH - each gwei is equal to 0.000000001 ETH (10^-9 ETH). For example, instead of saying that your gas costs 0.000000001 ether, you can say your gas costs 1 gwei. The word 'gwei' itself means 'Giga-wei', and it is equal to 1,000,000,000 wei. Wei itself is the smallest unit of ETH.

Gas Limit

This is the maximum amount of gas fee a transaction originator is willing to pay for their transaction, high gas limits give more room for complete and successful execution of the transaction. Any gas not used in a transaction is returned to the user (i.e max fee - (base fee + tip) is returned). For example, if you put a gas limit of 50,000 for a simple ETH transfer, the EVM would consume 21,000, and you would get back the remaining 29,000. A standard ETH transfer requires a gas limit of 21,000 units of gas. Too little gas fee is risky, reason because if the transaction requires more gas than specified, the state of the blockchain is reversed and miners still get paid for the work done, you lose at the end.

Why Gas Fees?

Gas fees help keep the Ethereum network secure. By requiring a fee for every computation executed on the network, also prevent bad actors from spamming the network. In order to prevent accidental or hostile infinite loops or other computational wastage in code, each transaction is required to set a limit to how many computational steps of code execution it can use. The fundamental unit of computation is "gas".

Why Gas fees can get so High

Ethereum is a fast-growing blockchain, most tokens are built on top of the ethereum blockchain. Performing any operation on Ethereum requires consuming gas, and gas space is limited per block. As Dapp,Defi,DAOs functionality grows more complex, the number of operations a smart contract performs grows too, meaning each transaction takes up more space of a limited size block. If there's too much demand which of course is currently happening, a user must offer a higher tip amount to try and out-bid other users' transactions. A higher tip can make it more likely that your transaction will get into the next block.

 
Share this