Ether Gas Limit & Gas Price save ether on your transactions

In this post Shawn uses an analogy to explain the difference between ether gas price, gas limit and Gas. He provides various examples to understand how to use Gas Limit and Gas Price to get the most out of your Ether.This guide will help you:a) understand ether Gas Price & Gas Limit b) reduce and save on your ethereum transaction fee .

1

Ethereum: Gas Limit , Gas Price

"gas this, gas that.. bah! why so complicated?"

Conducting your first Ethereum transaction can be rather daunting. You would think it'd get easier as you begin to send out more transactions. But in reality, we find ourselves asking even more question:

What is Gas Limit?!

What is Gwei?

Why are we using so many different units!?!

It can be overwhelming – but if you're feeling "dumb": Don't. Gas Limit & Gas price have eluded even the smartest veterans in this space. A lot of people have lost unnecessary Ether because they entered their Gas Price and/or Gas Limit wrong.

But it's not that it's complicated; it's just requires a different "thought process" compared to what we are used to. For example, consider a Bitcoin transaction:

Ethereum Transaction Fee vs Bitcoin Transaction Fee

A bitcoin transaction fee depends on the size of the transaction and the number of pending transactions. It's that simple. All you really have to do is enter the destination address and the amount you want to send. There's no notion of "Gas limit" or ether Gas Price like how Ethereum does it.

So, why has Ethereum complicated the transaction process so much? Unlike Bitcoin, Ethereum has to also take the "size of the computation" into consideration. Remember, Ethereum's primary goal is decentralizedapplications (dApps) which uses Smart Contracts. Gas Limit and Gas Price were introduced to ensure that computationally-hungry smart contracts pay what they owe. We'll discuss this in more detail in a later chapter. Ultimately, the primary reason for the use of Gas Limit and Gas Price is that Ethereum wanted to be efficient, flexible & fair.

In the next section, I'll go over a simple analogy that will help you set your ether Gas Price and Gas Limit . When you're done you will be able to send out a transaction with more confidence – and even save on transaction fees!

Chapter 2 An analogy to e explain Gas Limit and Gas Price and the Out Of Gas Error in ethereum.

2

Ethereum: Gas Price & Gas Limit: An Analogy

Life's but a game

We're going to use an Arcade Game Analogy!

What is Gas?

Before we jump into the fun stuff – let's quickly make sure that we understand what is "Gas". I'll explain this briefly, because we'll be diving into it deeper later. For now, all you need to know is:

Gas a the unit of currency used by Ethereum to process your transactions.

You pay for Gas using your Ether.

Complex "transactions" may cost a lot more Gas.

It's as simple as that. But then you're probably wondering why we need Gas. Why can't we just pay for my transaction directly in Ether?

Why are transactions paid in Gas? (instead of Ether)

The simple one line answer is: Ethereum transactions are paid in Gas instead of Ether in order to decouple the cost of Gas from the fluctuating cost of Ether. But you may be wondering why we would want to decouple Ether and Gas. If so, read the hidden content below. If not, skip it!

Remember, Ethereum needs to process smart contracts as well. As you may already know, some applications eat up a lot more resources than others. Therefore, Ethereum assigns a cost to the type of computation an application wants to perform.

For example, a contract can have the following types of operations and associated costs

Single Execution Step: 1 Gas

Store A Value: 100 Gas ​

Call Another Contract : 20 Gas​

This allows Ethereum to “charge” more for contracts that are more complex. This is fair – since a Smart Contract with more/demanding operations will be using more network resources. Since Smart Contracts can be complex, Ethereum has automated detecting and applying the costs (the Ethereum Virtual Machine does this) . However, since the price of Ether fluctuates drastically, we would have to readjust the automation each time.

Hence, Ethereum sets a fixed cost to each type of operation an dApp performs. That fixed cost is measured in Gas. So each operation will always cost the same amount of Gas. Then, if the price of Ether fluctuates, the users/miners can adjust the price of GAS in relation to Ether.

This brings us to our Gas Price and Gas Limit in Ethereum!

Gas Limit & Gas Price: The Difference (An Analogy)

Far too many articles out there focus on the nitty-gritty details; and completely miss the point. We're not going to do that today. In this article we will focus on understanding the difference between Gas Price and Gas Limit. As soon as you're done with this guide, you will be able to:

Like I said, you need a different "thought process" when playing with an ethereum transaction fee. But the good news is you're already applying this thought process – and you don't even realise it. When? Well, a good example is when you go to the video game arcade!

Playing in a Video Game Arcade = Playing with Ethereum Transaction Fees

​Most modern day gaming arcades don't use coins/cash anymore. They use a "Gaming Card" which you can can fill up with "Game Tokens".

For example, let's say you pay $100 and get 100 Gaming Token loaded up into a single Gaming Card. Upon entering the arcade, you'll notice that every game has a different cost. Example:

Once your Gaming Card is depleted, you have to stop playing. You can go refill your card for another session – or call it a day. But eitherway, the Gaming Card will hold the maximum number of Gaming Tokens you'll use up in a given session. In an ethereum transaction, your Gas Limit is your gaming card.

Gas Limit: The Maximum Ether You'll Pay

Remember, Ethereum processes decentralized applications (dApps). Think of each dApps as a Video Game in the gaming arcade. Just like how each video game requires different tokens, each dApp requires a different amount of Gas to run. When your all the Gas in your "Gas Limit" is consumed – your ethereum transaction will stop processing (ever see the "Out of Gas error"?)

Running out of Gas is like running out of tokens in your Gaming Card. The total Gas represents the total Gaming Tokens you use.

Gaming Tokens = Gas

Game Card = Gas Limit

Gas Limit is like your Gaming Card – you can't spend more ether than your Gas Limit will allow.

Each game may cost 3 tokens, or maybe even 10 tokens. But since you have your Gaming Card loaded up – you simply swipe away and play.

Similarly, an Ethereum transaction may need 1000 Gas , 30,000 Gas or even 100,0000 Gas. It depends on the computational resources needed to run that smart contract. However, it's easier to simply not care about the total Gas a transaction needs – and instead say how much you're willing to pay.

This brings us to our next bit – the cost of each gaming token. This is represented by "Gas Price" and is measured in Ether.

Cost per Token = Gas Price (in Ether or gwei)

Gas Price: The Cost (in Ether) of Each Gas Consumed

Remember, you paid $100 for 100 tokens for the day. So, you essentially bought 100 Gaming Tokens at $1 each. But what if the Gaming tokens costed $3 each? Would you still buy 100 Gaming Tokens? How about if each Gaming Token costed $10 each? If the tokens costed $3 each, your Gaming Card cost you $300. And if the tokens costed $10 each – you'd be paying a whopping$1000 for your 100 tokens.

Similarly, you have to pay for each Gas used in Ethereum. The Gas Price is the cost in Ether that you will be paying for each Gas consumed during a transaction.

The ether Gas Price is amount of Gwei you pay for each Gas consumed by your ethereum transaction

Note: We are using Ether as a unit for Gas Price for the sake of simplicity. You will see "Gwei" being used on most interfaces. This is simply a denomination of Ether (like cents is to dollars)

Fortunately, Ethereum lets you set the ether Gas Price per transaction. So you can either set it to 1 Gwei, 3 Gwei , or even 100 Gwei.

Your Gas Price is the cost you're willing to pay for each GAS "consumed" by transaction.

Using Ether Gas Price & Gas Limit Together:

1) We can set the ether (gwei) amount that we are willing to pay for each Gas – Gas Price

2) We can set the total Gas we are willing to consume for a transaction – Gas Limit

Since it's extremely difficult to know how much Gas will be needed for a transaction, this allows us to set a combination that we are comfortable with. In the next section we will go over a few examples of setting your Gas limit and Gas Price in Ether.

Setting Your Gas Price & Gas Limit

You should now have a good understanding of the relationship between Gas, Gas Limit and Gas Price. In order to cement that understanding, let's go over a few examples of Ethereum Transactions.

First, a quick note on this weird term: Gwei.

What is Gwei?

You may be wondering what Gwei is. If so, read the hidden content below. If not, just skip this section and move on to the next: Setting Gas Price & Gas Limit

Gwei is simply the denomination (sub-currency) of Ether. It's like how Cents is the denomination for dollars. So when you're referring to Gwei, you're actually referring to Ether anyway.

Note: "Ethereum" is NOT a currency – Ether is the currency. And Gwei is a denomination of Ether.

Transactions on the Ethereum network cost only a tiny fraction of an Ether. Hence, it becomes difficult to convey Gas Price and Gas Limits in terms of Ether. Imagine having to say "the transaction costs 0.000000023" Ether each time. You'll lose track of zeros.

Setting Your Gas Price & Gas Limit

Below is a screenshot of how the ethereum transaction set up looks like in MyEthereum Wallet (MEW). As you can see, you can set the destination, the amount and the Gas Limit. The Gas Limit was set to 21000 by default (default values may change overtime)

But where is the Gas Price? Well, it's sorta ...hidden. To be honest, I'm not sure why MEW decided to hide Gas Price – perhaps they wants you to spend more Ether? Don't worry – Mango to the rescue!

Setting Your Gas Limit & ether Gas Price

You can adjust the ether Gas Price from the right top hand corner. As you can see, it's set in Gwei (scroll up to read on Gwei to Ether):

Setting ether Gas Price in MyEetherumWallet

Alright, we'll do a quick example transaction. Let's say you set the following values for your transaction (we'll use small numbers for simplicity)

Now, let's say you are conducting a simple transaction that consumes only 5 GAS in total .

This would cost you 5 Gwei. (1 Gwei per gas, and you consumed 5 Gas). The other 15 Gwei will get refunded back to you! And this key to understand! Your Gas Limit is NOT you're paying. It's simply the maximum you're willing to pay in total. Just like how your Gaming Card was the maximum you could pay/play in total.

The Gas Price is a bigger driver of your ethereum transaction fee.

Increasing ether Gas Price:

Again, let's assume you conduct the same transaction again. But this time you change your Gas Price but keep the same ether Gas Limit:

Gas Limit = 20

Gas Price = 3 Gwei

Your transaction still consumes only 5 GAS in total. But it will cost you 15 Gwei this time! Why? Because this time you're paying 3 Gwei per Gas Also, your ether Gas Limit was 20 so you will get 5 Gas worth of Ether refunded back to you.

How much ether will be refunded? Well, you set you Gas Limit to 20, and each Gas costs 0.000000003 Ether. Do the math! Email me if you're still struggling!

Setting Gas Price to Zero: Free Ethereum Transaction?

This s a cool trick (and golden nugget, if you managed to read this far!). Can you set your Gas Price to 0? No – but you can set it close to zero. For example, you can set your transaction up like this:

Gas Limit = 20

Gas Price = 0.000000001 Gwei

Yeap, you can set your Gas Price to a fraction of a Gwei (which is already a fraction of Ether). This will make your total Gas Price so negligible, that the Ether cost will be as close to zero as you could get.

Why would a miner accept a transaction fee so low?Miners have to fill their "blocks" with transactions in order to propose a new block. The block reward they get is worth significantly more than the amount earned from transactions. Transaction fees are more of a "bonus" or tip – although they could add up as well.

However, when the Ethereum Network low network traffic, there are fewer people competing to get into a "block". As such, the miners may be willing to accept simple transactions in order to fill up their block and win the block reward.

Gas Limit: Running "Out Of Gas" in Etheruem

Now, let's take yet another scenario. This time you increase your ethereum Gas Price to $5:

Gas Limit = 20 Gas

Gas Price = 3

This time everthing stays the same – but your transaction consumes 50 Gas in total (instead of 5 Gas)

So, what's gonna happen? Your transaction will not go through. Why? Because you need 50 Gas to see this transaction through – and you put a limit of 20 Gas. This is what's going to happen:

Your transaction will start processing the Smart Contract

It will use up Gas at a rate of 3 Gwei per Gas

As soon as it hits the 20 Gas Limit (that you set), it will stop

It will realise that it needs more Gas to continue, but it hit the limit so it can't go on

You'll get he dreaded "Out Of Gas" error .

To use our Arcade analogy: it's like your Gaming Card ran out of tokens: "Out of Tokens"

Setting Gas Limit: Too High or Too Low?

Most , if not all, interfaces will let you set your ether Gas Limit to whatever number you want. Below is a screenshot of the interface of MyEtherWallet. You may be using another interface, but the fields for Gas Limit and Gas Price should be available:

Setting Gas Limit on ether consumed - MEW

Gas Limit Too Low: Is 21000 Gas Limit enough?

However, if you set the ether Gas Limit too low, you risk losing the Gwei entered – and your transaction will not go through. Remember, the Gas Limit is the total amount of Ether that you are willing to pay. Hence, when you set your Gas Limit to 21000, you are essentially saying:

"21000 Gas is the maximum amount that I am willing to spend on this transaction"

Therefore, if your transaction ends up costing more than 21000 Gwei, it will not go through. Here's the part that sucks: You will also lose your 21000 Gwei. Yes, really. I'll explain how & why soon. It's why you have to be careful if you're stringent on your funds.

Gas Limit Too High

On the other hand, you're pretty safe if you set your Gas Limit too high. As long as:

You don't set your Gas Price too high

Your transaction isn't super expensive.

If your gas price is reasonable, you can set a high gas limit and get away with it. Why? Because you will get refunded the rest of the gas. For example, let's say you want to ensure that your transaction gets through. So you double the ether Gas Limit and set your Gas Price to a meazily 1 Gwei. So you have:

Gas Limit: 42000 Gas Price: 1 Gwei

FAQ: Ether, Gas Price, Gas Limit

What is the current Gas Limit?

There is never a fixed Gas Limit. You can set the Gas Limit to whatever amount you want. However, you should be careful not to set your Gas Limit too low or you risk losing Ether.

Why is the Gas Limit Set to 21000?

Gas Limit is set to 21000 Gas by default in MyEthereumWallet and other interfaces. Gas Price is also set by default, so you should be careful to set that to an optimal number

What is the cost of Gas in Ether?

The cost of Gas is not fixed. It is always set by the user via the Gas Price parameter in Ether or Gwei units..

How do I convert Gas Limit to Ether?

The cost of your Gas Limit in Ether units will depend on the Gas Price you set. Simply multiply your Gas Price by the total Gas Limit. For example, if you set your Gas Limit to 21000, and your Gas Price to 2 Gwei. Your total cost in ether would be 21000 x 0.000000002 = 0.000042 Ether.

Phew, I think that covers it... If you have any more questions, please don't hesitate to contact me! Now we can move on to the fun stuff! In the next chapter we will cover some game theory in regard to transactions & mining; and overall transaction fee economics in general.