This article breaks down the concept of gas, gas limit and gas price, which is a central feature of the Ethereum (ETH) Blockchain and ecosystem.
If you’ve performed a simple transfer of Ether (ETH) from one place to another or participated in an Initial Coin Offering (ICO), then chances are you’re exposed to the concept of gas in the Ethereum network. Understanding the mechanics of gas and the associated terms “gas limit” and “gas price” is a crucial element to executing your ETH transactions. But before delving into the details of gas, it’s important to have a basic understanding of Ethereum.
(Read more: Coins, Tokens & Altcoins: What’s the Difference?)
Ethereum is a giant network consisting of a huge number of computers connected together. This large, interconnected web of computers is called the Ethereum Virtual Network (EVN) essentially a global, “supercomputer” where all transactions occurring in the Ethereum network are updated and recorded into each computer. Ether (ETH) is the native currency of the Ethereum blockchain and is used as the “fuel” for the network. ETH is not to be confused with Ethereum Classic; the latter is a fork of the Ethereum Blockchain. Here’s a guide to understanding forks, hard forks and soft forks.
A revolutionary functionality of the Ethereum blockchain was the introduction of smart contracts. Smart contracts are any contracts that have been pre-programmed with a set of definitive rules and regulations that are self-executing, without the need of any intermediaries. Therefore, with any given inputs, there will be a known output. As they say:
Code is King
Here’s simple (hopefully!) breakdown of a smart contract:
Why Is Gas Needed?
Ether tokens (ETH) are publicly traded on exchanges and its market price can fluctuate rapidly. The creation of gas units is to separate the cost of computation work in the Ethereum network from Ethereum’s volatile market price, as the cost of computation DOES NOT change rapidly. Imagine paying a flat fee calculated directly in Ether when it’s market price was $10 and to send an ETH, you needed to pay half an ETH ($5) a year ago. Now, the price of ETH is at $1,000. Would you want to pay $500 (0.5 ETH) for exactly the same transaction? That’s why the gas system was created. (See also: Bitcoin vs Alt Coins Returns: Comparison of Gains Between Bitcoin & Altcoins Investing)
What is Gas?
Gas is a unit of measuring the computational work of running transactions or smart contracts in the Ethereum network. This system is similar to the use of kilowatts (kW) for measuring electricity in your house; the electricity you use isn’t measured in dollars and cents but instead through kWH or Kilowatts per hour.
It is important to understand that different kinds of transaction require a different amount of gas to complete. For instance, a simple transaction of sending ETH from one place to another cost 21,000 Gas while sending ICO tokens from your MyEtherWallet (MEW) wallet costs much more due to higher levels of computation ended. Here’s a guide on opening a MEW wallet, which is a wallet that supports ETH and ERC-20 coins.
Execution of the smart contracts is done by a miner, who spends their own time, electricity and computing hardware to execute the codes and finalize the transaction
Gas limit refers to the maximum amount of gas you’re willing to spend on a particular transaction. A higher gas limits mean that more computational work must be done to execute the smart contract. A standard ETH transfer requires a gas limit of 21,000 units of gas.
The more complex the commands you want to execute, the more gas you have to pay. You can see this in action when participating in an ICO that requires you to send ETH into its smart contract or when you want to withdraw your ICO coins to an exchange; the fees of transfer are much higher than the default 21,000 gas limit. This is because the smart contracts of an ICO possess much more complex codes and require much more computation than a simple ETH transfer.
Gas limit acts as a safety mechanism to protect you from depleting your funds due to buggy codes or an error in the smart contract. As an analogy, gas limit is similar to your car’s fuel tank capacity.
What if You Specify Too Little Gas?
Your transaction will be initially executed by the miners, but once gas runs out the miners will STOP performing work on your transaction. The blockchain will record the transaction as “Failed”, and your ETH will still be in your wallet since there was insufficient gas to fully execute the transfer. The gas used for the failed transaction will be kept by the miners for their work and you WILL NOT get it back. Here’s what’ll happen if you specified too little gas.
You don’t have to worry about setting the gas limit value as MyEtherWallet (MEW) and Metamask would automatically set the default gas limits for the types of transactions you’ll engage in.
Gas price refers to the amount of Ether you’re willing to pay for every unit of gas, and is usually measured in “Gwei”. An analogy for gas price – relating to the previous analogy for gas limits – is that it is similar to the cost of each litre of fuel that you’re paying for filling up your car.
Wei is the smallest unit of Ether, and a Gwei consists of a billion wei. Before entering you’re the gas price that you want to set, it’s always good to look at current gas prices from ETH Gas Station. Here’s what it will look like:
Here’s a breakdown of the terms:
Std (Standard) Cost for Transfer: Average fees that users pay to transfer ETH – in USD value – for a standard priority transaction (usually a waiting time of fewer than 5 minutes)
Gas Price Std (Gwei): Average fees that users pay to transfer ETH – in Gwei value – for a standard priority transaction (usually a waiting time of fewer than 5 minutes)
SafeLow Cost for Transfer: Average fees that users pay to transfer ETH – in USD value – for a low priority transaction (usually a waiting time of fewer than 30 minutes)
Gas Price SafeLow (Gwei): Average fees that users pay to transfer ETH – in USD value – for a low priority transaction (usually a waiting time of fewer than 30 minutes)
Median Wait (s): Average waiting time for a single transaction in seconds
Median Wait (blocks): Average waiting time for a single transaction in blocks
(Read more: Evolution of Cryptocurrency: What is Cryptocurrency?)
Can I Speed Up My Transaction?
If you’re wondering what’s the difference between a low priority and a standard priority transaction, here’s a table extracted from ETH Gas Station to help you understand better:
You can actually choose the priority level of your transaction. Miners will “work on” and execute transactions that offer a higher gas price, as they’ll get to keep the fees that you pay. Therefore, they will be incentivized to prioritize transactions that have a higher Gwei.
If you want your transaction to be executed at a faster speed, then you have to be willing to pay a higher gas price. You’re essentially “jumping the line”, beating everybody that paid a lower gas price. Based on the above table, you have to pay 8 Gwei if you want your transaction to be finalized within 2 minutes. It all depends on your urgency.
Putting It All Together
Let’s take a look at an example of an Ethereum transaction to see how the concepts of gas, gas limit and gas price come together:
Looking at this transaction at Etherscan, we can see the breakdown of all terms associated with gas. Here’s what they mean:
Gas Limit: Maximum amount of gas that a user will pay for this transaction. The default amount for a standard ETH transfer is 21,000 gas
Gas Used by Txn: Actual amount of gas used to execute the transaction. Since this is a standard transfer, the gas used is also 21,000
Gas Price: Amount of ETH a user is prepared to pay for each unit of gas. The user chose to pay 8 Gwei for every gas unit, which is considered a “high priority” transaction and would be executed very fast
Actual Tx Cost Fee: This is the actual amount of fees that the user will pay for the transaction in Ether value (USD value is in brackets). Not bad; the user paid a total of 14 cents for his ETH to be transferred in less than 2 minutes!
In summary, the ultimate formula to calculate the amount of fees you’ll end up paying for a transaction is:
Transaction (Tx) Fees: Gas Used by Txn * Gas Price
From the above example, we can see that the actual gas consumed in executing the transaction is 21,000 gas while the gas price chosen by the user is 8 Gwei (0.000000008 ETH). Multiply both figures together and you’ll get the actual cost of executing the transaction, amounting to 0.000168 Ether (USD $0.14).
It is important to note that the gas limit can be (and is usually) more than the actual gas used in the transaction. In times of an ICO, the average gas price will tend to be exponentially higher as people will be rushing to participate in the ICO. This would lead to more people increasing their gas prices to have a better chance of confirming their ICO transaction.
If you’re starting your journey into the complex world of cryptocurrencies, here’s a list of useful resources and guides that will get you on your way:
Trading & Exchange
- Crypto Guide 101: Choosing The Best Cryptocurrency Exchange
- Guide to Bittrex Exchange: How to Trade on Bittrex
- Guide to Binance Exchange: How to Open Binance Account and What You Should Know
- Guide to Etherdelta Exchange: How to Trade on Etherdelta
- Guide to Cryptocurrency Wallets: Why Do You Need Wallets?
- Guide to Cryptocurrency Wallets: Opening a Bitcoin Wallet
- Guide to Cryptocurrency Wallets: Opening a MyEtherWallet (MEW)
Get our exclusive e-book which will guide you on the step-by-step process to get started with making money via Cryptocurrency investments!
You can also join our Facebook group at Master The Crypto: Advanced Cryptocurrency Knowledge to ask any questions regarding cryptos!