What is Gas and Transaction Fees? [Ethereum Guide]

in #bitcoin7 years ago (edited)

Here are the basics (in-depth explanations are further down):
MyEtherWallet Behind-The-Scenes (Image)

Gas Price: How much youre willing to pay miners to mine your TX before others

Gas Limit: The amount of gas required to compute your TX. Prevents you from wasting space on chain & allows contracts to fail instead of looping infinitely

TX Fee: Limit * Price

If you're using MyEtherWallet:

Gas Price: Change in top-right. Higher gas price=faster=more expensive

Gas Limit: Change when sending. Auto calculated based on who + what you are sending (ETH vs Token)

@ETHGasStation allows you to see how full network is & recommends gas price based on network conditions

In-depth explanations from MyEtherWallet's knowledge base:
Introduction
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 computation, 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 (gas limit * gas price) in ETH & USD when you search for your transaction on etherscan.io. This is not a TX fee that MyEtherWallet, or any other service provider, receives. This fee is paid to miners for mining transactions, putting them into blocks, and securing the blockchain.

Overview
When you hear gas, the person is either talking about:

Gas Limit
Gas Price
The total cost of a transaction (the "TX fee") is the Gas Limit * Gas Price.

Typically, if someone just says "Gas", they are talking about the "Gas Limit".

Analogy Time!

You can think of the gas limit like the amount of liters/gallons/units of gas for a car. You can think of the gas price as the cost of that liter/gallon/unit of gas.

With a car, it's $2.50 (price) per gallon (unit).
With Ethereum, it's 20 GWEI (price) per gas (unit).
To fill up your "tank", it takes...

10 gallons at $2.50 = $25
21000 units of gas at 20 GWEI = 0.00042 ETH.
Therefore, the total TX fee will be 0.00042 Ether.

Sending tokens will typically take ~50000 gas to ~100000 gas, so the total TX fee increases to 0.001 ETH - 0.002 ETH.

Gas Limit
The gas limit is called the limit because it's the maximum amount of units of gas you are willing to spend on a transaction. This avoids situations where there is an error somewhere in the contract, and you spend 1 ETH....10 ETH....1000 ETH..... going in circles but arriving no where.

However, the units of gas necessary for a transaction are already defined by how much code is executed on the blockchain. If you do not want to spend as much on gas, lowering the gas limit won't help much. You must include enough gas to cover the computational resources you use or your transaction will fail due to an Out of Gas Error.

All unused gas is refunded to you at the end of a transaction. So if you go to MyEtherWallet, send 1 ETH to our donation address ( ? ), and use a gas limit of 400000 you will receive 400000 - 21000* back. However, if you were sending 1 ETH to a contract and your transaction to the contract fails (say, the Token Creation Period is already over), you will use the entire 400000 and receive nothing back.

*21000 is the gas limit for standard transactions

Gas Price
If you want to spend less on a transaction, you can do so by lowering the amount you pay per unit of gas. The price you pay for each unit increases or decreases how quickly your transaction will be mined.

During normal times:

40 GWEI Gas Price will almost always get you into the next block.
20 GWEI will usually get you within the next few blocks.
2 GWEI will usually get you within the next few minutes.
During Token Creation Periods, these costs go crazy due to supply / demand:

50 GWEI is the max gas price most new Token Creation Period contracts will accept. Anything above that and your TX will fail. Most is the keyword here—check with the Token Creation Period you wish to invest in before said Token Creation Period begins.
50 GWEI would be the amount you should send in that case.
If you are trying to send during an Token Creation Period (but not to the Token Creation) you have 2 choices: wait a bit until the Token Creation Period is over, or increase the gas price over 50 GWEI.
Further explanations, use cases, and scenarios can be read on MyEtherWallet's knowledge base article.

Sort:  

Congratulations @kneeshaw! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @kneeshaw! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.028
BTC 57184.88
ETH 3097.33
USDT 1.00
SBD 2.41