An Investor end up paying 236 ETH ($122,086) gas fees for a simple Ethereum Tx
Back in October’17, an investor sent 1,700 ETH to a contract (AirSwapDEX) with a gas price of 400,000 Gwei and gas limit of 592,379. The Tx failed for some odd reason but the investor was charged whopping 236 ETH ($122,086 as per today’s price) gas fees (Tx fees) for processing the transaction on ETH blockchain.
Today, I completed a successful transaction of transfering ETH (21,000 gas limit) with just 1 Gwei. It cost me $0.01.
If I did the same what that investor did, I would have charged 400,000 times more i.e. — 0.01 * 400,000 = $4,000. That’s 8.4 ETH for sending 1 ETH.
Shocking. Someone is paying more and Tx failed, others are paying less and Tx passed.
The purpose of this article is to help you understand “how gas (tx fees) works” is crucial for Ethereum users who are participating in ICOs, using smart contracts, and even making simple transfers between wallets to save tons of money (ETH) while interacting with ethereum blockchain.
Ethereum is the network, also known as the blockchain. Ether (ETH) is the fuel for that network. When you send tokens, interact with a contract, send ETH, or do anything else on the blockchain, you must pay for that computation. That payment is calculated in Gas and gas is paid in ETH.
You are paying for the computational power used by super computers (miners) to add your transaction in blockchain, regardless of whether your transaction succeeds or fails. Even if it fails, the miners must validate and execute your transaction (compute) and therefore you must pay for that computation just like you would pay for a successful transaction.
You can see your TX fee (also referred as gas) in ETH & USD when you search for your transaction on etherscan.io.
This is not a TX fee that MyEtherWallet, or Metamask, or any other service provider, receives. This fee is paid to miners for mining transactions, putting them into blocks, and securing the blockchain.
WTF is Gas Price and Gas Limit?
Let’s drive a car.
Suppose, it costs 2 litres of petrol to drive a car to a known place and you paid Rs 25 per litre. It equates to:
2 * 25 = Rs 50.
Similarly, it will cost 21,000 gas limit to make a Ethereum transfer and you paid 10 Gwei gas price per gas limit. It equates to:
21,000 * 10 = 210,000 Gwei (smaller unit of ETH)
Now, if you burned 10 litres of petrol driving your car, you’ll be charged:
10 * 25 = Rs 250
If you make a more intense Tx on Ethereum blockchain like participating in an ICO, you’ll be charged more. Let’s assume 100,000 limit and and again you paid 10 Gwei for each limit.
100,000 * 10 = 1,000,000 Gwei
There is no need to increase the Gas price of Tx for bigger transaction, instead just increase the gas limit.
Gas Price — It’s the price you’re ready to pay for each computational power (which is calculated in gas limit) used by miners, paid in ETH.
Gas Limit — It’s the numeric representation of computational power consumed by miners.
TX fee — Gas Limit * Gas Price.
How does the computational power calculated?
The computational power (gas limit) necessary for a transaction is already defined by how much code is executed on the blockchain.
You’re charged for each calculation like adding 2 + 5 in a smart contract function or for transferring 1,000 shitcoins to your Ethereum Address after participating in a Coin Offering Crowdsale contract.
If you do not want to spend as much on gas, lowering the gas limit won’t help because gas limits are pre-defined on the smart contract which is immutable (can’t be changed).
Following is a comprehensive list of gas limits consumed for different operations:
- 2 gas limit — Many management operations — what time is it, what’s the balance in the transaction, what’s the address, etc.
- 3 gas limit — Addition, subtraction, logical negation and tests, bitwise operations, loads and stores to temporary memory (per machine word, i.e. 256 bits), stack manipulation.
- 5 gas limit— Multiplication, division, modulo, sign extension.
- 8 gas limit — Add-mod-N, multiply-mod-N, unconditional jumps.
- 10 gas limit — Conditional jumps.
- 200 gas limit — Load word from permanent storage: 200 gas.
- 20,000 gas limit — Store word to permanent storage.
- 32,000 gas limit — Create new contract or transaction.
Interested users can check Ethereum yellow paper (page 20) for indept details.
21,000 units is the minimum limit for all the Ethereum Tx and other operations are charged above 21,000 units.
Here’s a simple ETH transfer operation.
So if you’re calling a function which stores a value in permanent storage of a smart contract, it will cost you 21k + 20k = 41k gas limits * x gas price.
You must include enough gas to cover the computational resources you use or your transaction will fail due to an Out of Gas Error, regardless of how high you’re paying (even if you pay millions for Tx, it will not go through).
How do I calculate the gas limit?
You don’t need to. The ethereum wallet client (MEW, Metamask etc) will automatically calculate the gas limit for you. However, you have choice to change the limits and price.
What if I send Tx with “more than needed” gas limits?
You’ll get the refund of unused gas limits.
So if you send ETH with 100,000 gas limits to your friend’s address, you’ll be only charged for 21,000 gas limits. Remaining gas limit (79,000) will not be used and hence not deducted from your ethereum address.
Check the image from etherscan below with how much gas limit is sent and how much is charged.
How to calculate the gas price (not gas limit)?
It’s a value you’re willing to pay. If you pay high, miners will pass your Tx quickly and if low, it may get delayed.
However, to get an estimate of how much gas price miners are willing to accept, visit ETH Gas Station. I provide statistics related to ethereum gas price and very helpful to set gas price while making any ethereum Tx.
At the time of writing this article, the website says that you need 1 Gwei to get your Tx confirmed within 5 minutes and 3 Gwei for within 1 minute. Next time, don’t end up giving 60 Gwei irrationally. Do visit the website before initiating any Tx.
This article is inspired by the community at our crypto project, MoatFund — a Fund Managing Protocol on Ethereum Blockchain.
We observed that most of the MoatUnits investors paid 60 times more Tx fees than what needed to participate in our Unit Offering and some Tx failed due to low gas limit.
Remember, Out Of Gas error only occur if your gas limit is not enough to cover the Tx. You can even shoot a simple ETH transfer Tx with 0.1 Gwei of gas price and 1,000,000 of gas limits — you’ll be only charged:
0.1 * 21,000 = 2,100 Gwei
But if you set 1,000 gas price with 20999 gas limit, your Tx will get failed as well as you’ll be charged:
1,000 * 20,999 = 20,999,000 Gwei
That’s approx 10,000 times more and still Tx got failed.
Your car will not move even an inch after your remaining petrol is 0 litre, no matter how expensive petrol you bought earlier. Instead better you buy appropriate petrol to cover the distance at market price.
I hope, you understood, what I’m trying to point out.
And to be honest, it takes very less fees to proceed a similar Tx.
MoatFund is a crypto fund, build on Ethereum blockchain based ERC20 Standard. Moat Units shows the Proof of Membership in MoatFund. You invest in Moat Units and the funds will be allocated in different research-backed crypto coins.
Want to Invest in MoatFund? Participate in the MoatUnit Offering at our website — https://moatfund.com