Simply Explained: Ethereum Gas (2024)

Just like the gas you put in your car, almost.

<article>

<definition>

For those of you already familiar with Ether transactions, you’ve probably heard of gas. It pops up in your MetaMask when you make a transaction, saying the “gas limit” is something like 21000 and the “gas price” is 1. So what does that all mean?

Well, gas is a unit that measures the use of computational power in the Ethereum network. That is, how much effort computers processing a certain operation will need to put in to successfully execute the operation. Operations in Ethereum are, for example, sending Ether to another address, publishing a contract, calling a function on a contract, among others. When these happen, miners process that information in the EVM (Ethereum Virtual Machine) to reach the proper outcomes, such as executing a function and returning the right data or sending the ETH to the right address. In doing this, these miners are using their computational power, and the more complex a transaction is, the more power it will consume, hence using more gas.

Simply Explained: Ethereum Gas (2)

Gas limit

Gas limit defines the maximum amount of gas an operation can use. For example, when sending some Ether from Alice to Bob, the gas limit is usually set at a standard of 21000, assuming no more data is included in the transaction. 21000 is the minimum amount of gas an operation on Ethereum will use. This limit is used to guarantee that the transaction will be executed. The limit is usually provided by the clients/wallets, which estimate the maximum boundary for gas use of an operation, to assure that it will be executed properly without the user having to worry. In this case, the unused Ether used to pay for the extra gas will be returned to your account if the operation uses less gas than the limit. While many times the limit is set for you, it can also be set manually, in which case the user runs the risk of the operation failing, if the limit is not enough.

More complex operations will use up more gas. See the example list below, ordered from lowest to highest gas requirements.

  1. Sending Ether to another address
  2. Sending Ether to another address with some added metadata
  3. Calling a function on a smart contract
  4. Publishing a simple smart contract
  5. Publishing a complex smart contract

Lastly, if you want to know how the gas limit of an operation is calculated, the formula provided by the Ethereum Yellow Paper is as follows:

gasLimit = G(transaction) + G(txdatanonzero) × dataByteLength

Gas price

Gas price is the comparative equivalent of the miner fee in Bitcoin. In Bitcoin, you choose how much you want to pay the miner to process your transaction, being so that the higher the fee, the faster the transaction will be included in a block (in general, assuming participants rationally follow the financial incentive structure).

In Ethereum, things work similarly. Once the gas limit for a transaction is set, you can choose how much you wish to pay for each unit of gas. The more you pay, the faster you expect your operation to execute. Gas price is most often calculated in Gwei, a subunit/denomination of Ether, equal to 1/10⁹ ETH. Usually, when operating in the mainnet, users will pay between 1–60 Gwei per unit of gas, depending on how overloaded the network is.

Hence, the equation for how much in Ether you will pay in “network fees” is:

cost (ETH) = gasLimit × gasPrice × (1/10⁹)

Example — Alice sends 2ETH to Bob, choosing a gas price of 2 Gwei:

21000 × 2 × (1/10⁹) = 0.000042 ETH

Important note: The gas price is not selected by the network. It is chosen by the user, or sometimes, by the client, which shields the user from this information and sets a standard gas price, for the sake of usability (yet often at a higher cost for the end user).

For future reference, you should check the following website:

The website tells you what it calls the “SafeLow Cost for Transfer”, which is the minimum gas price you should set to have a high chance of your transaction being included in one of the next blocks (usually over 90% chance of it being included in the next 10 blocks).

As a rule of thumb, you should set higher gas prices for urgent transactions, and lower prices for transactions you don’t mind taking a while to confirm.

It is also worth noting that if your gas limit is set at, for example, 300000, you choose to pay 40 Gwei for each unit of gas, and ultimately, the transaction only uses 21000 gas, you will be refunded:

[(300000–21000) × 40 × (1/10⁹)] = 0.01116ETH

The takeaway here is: you are refunded for unused gas, accounted for the price you paid for it, but you are not refunded for setting the gas price too high.

</definition>

<questions>

Simply Explained: Ethereum Gas (3)

Why not set enormous gas limits for every transaction?

So to guarantee my transaction will not run out of gas, I can set the gas limit extremely high, right?

Yes, you can. The problem with doing so is that you will have to pay a lot of Ether up-front, which you may not have or that you might need while your transaction is being processed. It is also a question of optimization.

However, you can, and should, put the gas limit slightly higher than the amount of gas you expect the transaction to consume when dealing with gas limits manually.

Common errors

“Transaction underpriced” or “transaction fee too low”

Means that your gas price is set too low and your transaction may not confirm, or will take too long too confirm, since it will always be at the end of the list of transactions to be included in the next block. Wallets will often offer you the option to increase your gas price to change this, or refuse to send the transaction.

“Transaction ran out of gas”

Means that the gas limit was set too low, and the transaction ended up using more gas than you paid for. Transactions with a lower gas limit than the gas used will never execute. In this case, you will not be refunded the Ethers spent. That is because the miner used valuable computational power to attempt to execute the transaction, but was unable to. Regardless of the transaction confirming or not, computational power was used, and it was paid for.

Gas limit of blocks

Instead of implementing a hard memory limit on blocks, like Bitcoin’s 1MB, Ethereum sets its block limits with gas. The current limit is set at 8000000 units of gas per block, but it is in fact not a hard limit, but a parameter the network follows as a mean limit for blocks. Blocks can be over the limit, but ultimately, the network aims to keep the average below 8000000. There is discussion regarding setting this limit in the actual protocol, with the benefit of preventing blocks from being too large and hard to compute, especially for nodes with less computational power available. The counterargument is that this limit may prevent complex dApps which consume a lot of gas from running.

More on that here and here.

Gas and smart contracts

Smart contracts require gas to run and execute its functions. The more complex a contract or function are, the more gas they will use. Because of this, optimization of smart contracts is extremely important, to prevent excess use of gas, which is costly, and overloads the network for no reason.

Commonly, Remix’s static analysis of contracts will return a warning regarding the high gas requirements of a function. It is also important to watch out for loops, which can consume excessive gas.

Publishing complex contracts will use more gas than publishing simpler contracts, and the same applies to the execution of these contracts.

Why are these fees important?

These fees are important because they provide a fair incentive scheme for keeping the network running properly, since the more you utilize the network, the more you pay for it. But perhaps most importantly, it helps protect the network against attacks (namely DDoS attacks), since malefactors will have to pay a high price to harm the network.

</questions>

</article>

Simply Explained: Ethereum Gas (2024)

FAQs

Simply Explained: Ethereum Gas? ›

Gas is the fee required to successfully conduct a transaction or execute a contract on the Ethereum blockchain platform. Fees are priced in tiny fractions of the cryptocurrency ether (ETH)—denominations called gwei (10-9 ETH). Gas is used to pay validators for the resources needed to conduct transactions.

Why is ETH gas so high right now? ›

⛽️ Gas fees are paid to Ethereum miners to process transactions on the blockchain network. 🔥 Gas fees can be high during periods of high network congestion or when demand for transactions is high. 📈 The price of gas is determined by the market, based on supply and demand for network resources.

How much gas is 1 gwei? ›

Its nickname is “shannon,” after Claude Shannon, the scientist and cryptographer known as “the founder of information theory.” Specifically, a unit of Gwei is defined as one-billionth (one Nano) of Ether. So 1 Gwei equals 0.000000001 or 10-9 ETH. Conversely, 1 ETH equals one billion (109) Gwei.

What is Ethereum in layman's terms? ›

Ethereum is a decentralized blockchain platform that establishes a peer-to-peer network that securely executes and verifies application code, called smart contracts. Smart contracts allow participants to transact with each other without a trusted central authority.

How do you explain crypto for dummies? ›

Cryptocurrency is digital money that doesn't require a bank or financial institution to verify transactions and can be used for purchases or as an investment. Transactions are then verified and recorded on a blockchain, an unchangeable ledger that tracks and records assets and trades.

Where do ETH gas fees go? ›

The gas fees go to crypto miners whose computers are used to validate blocks of transactions on the Ethereum blockchain network. Gas is paid in Ethereum's native currency, Ether, which is the actual cryptocurrency that investors trade on a crypto exchange app.

What time of day is ETH gas cheapest? ›

Ethereum gas prices vary a lot, even from one hour to another. Statistically, it's been shown that the lowest gas prices can be found in the mornings and on the weekends.

Why is gas important in Ethereum? ›

Ethereum gas is a blockchain transaction fee paid to network validators for their services to the blockchain. Without the fees, there would be no incentive for anyone to stake their ETH and help secure the network.

How do I convert GWEI to USD? ›

To calculate the price in terms of USD, multiply your total gwei by the current price of one Ether divided by 1,000,000,000 (10^9). For example, if Ether is worth $1,000, then 420.069 gwei equals $0.000420069, or approximately 1/25th of one cent.

Who owns the blockchain? ›

Nobody 'owns' blockchain technology. But some 'blockchains' may be owned by specific organizations.

Can I convert Ethereum to cash? ›

There are many ways to turn Ethereum into cash. Each method has its own steps, how long it takes, costs, taxes, and risks. You can send Ethereum to online exchanges, trade with others, use Ethereum cash machines, or spend with crypto debit cards.

Who controls Ethereum? ›

The Ethereum platform was developed by a community of users and developers. These people collectively drive the development of the platform. Ethereum is not controlled by any one person, entity, or group. Ethereum exists solely through the work and effort of its community, who collectively operate the Ethereum network.

Does Ethereum have a future? ›

As witnessed in 2021, ETH outperformed BTC, gaining nearly 400% compared to Bitcoin's 66%. Experts acknowledge that due to several use cases and its unique blockchain, Ethereum has a stable future, and there is a chance it may perform exceptionally well compared to Bitcoin.

What's the difference between Bitcoin and Ethereum? ›

Ethereum and Bitcoin are both cryptocurrencies, so either could work for any transaction in which both buyer and seller are comfortable using it. But overall, Bitcoin is intended as more of a general-purpose currency for everyday payments. Ethereum is designed explicitly for payments on the Ethereum network.

How is Ethereum used in real life? ›

One of the main real-world use cases for Ethereum is decentralized finance (DeFi) applications. Here we can find a wide variety of functionalities ranging from decentralized lending (based on smart contracts), decentralized exchanges and the creation of stablecoins.

Is it easy to learn Ethereum? ›

However, learning the Ethereum environment is hard. It looks very similar to javascript, or pretty much any curly bracket language derived from c. If statements, for loops, class inheritance, variable types, are all very familiar.

Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 6189

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.