Brought to you by the Liquid team to help you make sense of crypto.
Gas provides the fuel that keeps the Ethereum blockchain running 24/7.
Every action that takes place on Ethereum (whether it’s a transaction, token sale or a hard fork) requires gas.
Gas helps Ethereum calculate the fees needed to execute a given action, and it ensures load-balancing across the network.
In this piece, we’re going to take a look at what gas is and dive deep on why it’s important to Ethereum’s present and future state.
We’ll also analyze how the price of gas can impact mining performance and clearly outline the difference between gas cost and gas price.
What is gas?
Put simply, gas is the fuel of the Ethereum blockchain.
Specifically, it’s a unit of measurement that defines the amount of processing effort required to execute a given action on the Ethereum network.
Every instruction that’s dictated by a smart contract on the Ethereum network requires gas, and once the required amount of gas is transmitted to a smart contract, then a given set of instructions will be executed.
Why is gas important to Ethereum?
Gas is critical to the functionality of Ethereum because it provides a method of incentivization that attracts more miners to the network.
When a P2P network like Ethereum has more miners, it also has a higher hashrate, which makes the system more robust and secure.
Miners earn tokens by mining blocks, but they can also earn tokens by temporarily controlling their mined blocks and exploiting them for profit.
When miners mine a block and encode it, computational power is also required to validate those contracts, and Ethereum’s gas functionality allows them to charge a fee for this, which can become a separate income stream in and of its own right.
Gas provides an absolutely critical method of incentivization on the Ethereum network.
How Ethereum’s gas limit works
Every transaction made on the Ethereum network must have a gas limit specified before taking place.
While the amounts involved can be infinitesimal, it’s helpful to think of the gas limit as the absolute maximum someone is willing to pay for a transaction.
The transaction fee (gas price) is generally dependent on the complexity of the transaction involved. Simple actions like sending Ether to a friend will likely incur a relatively small gas charge, while creating a smart contract to be used in a token sale will be far more costly.
The more complex a transaction is, the more gas you will need to pay to execute it.
As laid out previously, a gas limit needs to be specified in order for a transaction to occur. This means that the person looking to execute that transaction needs to set the gas limit first.
If doing this yourself, it’s worth keeping in mind that every transaction has a different gas cost (for more insight into how much gas each type of transaction requires, see the Ethereum Yellowpaper).
That said, the actual amount of gas used in each transaction is variable. As an example, this means that even if transferring ETH to a friend could in theory require 120 gas, the network may actually only end up using 100 gas to complete the transaction.
If there is gas left over at the end of a transaction, it’s immediately refunded to the person who initiated that transaction.
This refund represents one way that miners can earn tokens for their efforts.
But there’s another scenario, one where the gas limit specified by the end user is not enough to execute a given transaction. When this occurs mid-transaction, the operation in question will “run out of gas” and turn back to its original state.
However, the person who initiated the transaction still has to pay the full gas fee, and the transaction itself still gets added to the Ethereum blockchain (even if it hasn’t been completed).
What’s the difference between gas limit and gas price?
The gas limit is the maximum amount of gas that you are willing to spend in order to complete a transaction.
While the standard gas limit for most transactions is 21000, this can vary depending on the complexity of the transaction.
Since the gas limit is defined by the Ethereum network, you won’t be able to undercut the amount required for a transaction; you’ll need to pay the full amount of gas, every time.
If you don’t set your gas limit high enough before initiating a transaction, you’ll receive the dreaded “out of gas” error and use up the gas limit set at the beginning of the transaction as well.
Gas price, on the other hand, is an adjustable amount that represents the amount one pays per unit of gas. Gas price will go up and down depending on how quickly you want a transaction mined (or executed).
Lowering the amount of gas price paid will also lower the total cost of a given transaction, but it’ll also ensure it takes longer, too.
Paying a higher gas price will ensure a transaction is prioritized in the blockchain, while in most cases, paying a lower gas price will essentially ensure that a transaction won’t take place for at least a few minutes.
Keep in mind that the price of gas is subject to supply and demand as well. During times of high demand (like Token Creation Periods), the gas price required to execute a transaction will be higher than
How gas price impacts mining performance
Miners collect any transaction fees involved when mining your block. Higher gas prices naturally attract miners, given that they represent a higher reward for successfully mining a given block.
With that in mind, it’s often helpful to set the gas price for a transaction high enough to be enticing for miners.
Given that most miners prioritize transactions by gas price, this is a good rule of thumb to use. Setting the gas price higher will ensure your transaction is processed faster, but it’ll also guarantee that the price will be higher as well.
A lower gas price is generally less enticing to would-be miners, so transactions that have a lower gas price will usually take longer to complete.
If you’re looking to complete a transaction as cost-efficiently as possible, then setting a lower gas price may be a great idea.
If you’re interested in seeing how long it will take for your transaction to be completed given a certain gas price, this calculator is a great way to get some insight.
Gas can be mined for insights
Gas also acts as an important source of data around the health of the blockchain.
Since the gas details of all transactions are transparently stored on the blockchain, one can gain a significant amount of insight on the state of the blockchain by analyzing the gas prices of recent transactions.
For example, looking at the average gas price of transactions can give one greater insight into user behavior, as well as their preferences for incentivization.
For blockchain developers, this can prove especially useful as it’s a good way to do market research and gauge potential transaction performance prior to developing a Dapp or launching a token sale.
Pros and cons
Gas limits have provoked debate in the community due to their significant costs and benefits.
On one hand, the presence of gas limits ensures that miners are fairly compensated for their work and regulates supply and demand on the network.
It performs the critical function of load balancing, something that would be difficult to do without a gas limit in place.
On the other hand, gas limits also ensure that adding data to the blockchain is both costly and time-consuming for many.
While the current state of adding data to the Ethereum blockchain is somewhat inefficient, numerous efforts to scale the platform are underway, and this gives many hope that gas limits will gradually decrease as time goes on and the network becomes more efficient.
Gas limit: The gas amount required (in terms of ETH) for a given transaction. This represents the maximum amount of gas that can be used for a given transaction.
Gas price: The gas price in ETH defined by the person initiating the transaction. Higher gas prices generally mean that transactions will be completed faster, while lower gas prices ensure they will take more time.
Cumulative gas used: The total amount of gas used to complete a transaction (including gas from previous transactions, where relevant).
This content is not financial advice and should not form the basis of any financial investment decisions nor be seen as a recommendation to buy or sell any good or product. Trading cryptocurrency is complex and comes with a high risk of losing money, particularly if you trade on leverage. You should carefully consider whether trading cryptocurrencies is right for you and take the time to learn how trading works and decide how much money you are prepared to lose.
Providing liquidity for the crypto economy.