What is Gas and How is it Used? (2024)

Gas in Ethereum refers to the additional fee required to execute a smart contract or transaction on the blockchain network.

Why does this exist?Well, there's a couple major limitations when it comes to running smart contracts:

  1. Every deployed transaction, smart contract, or execution of a smart contract, must be run on every single full node on the Ethereum blockchain to guarantee validity. This is wildly inefficient (though newer blockchains are streamlining this)!
  2. Because smart contracts are Turing complete, they can potentially execute forever, locking up every single node on the blockchain.

What is Turing completeness?

Practically, a programming language that is Turing complete is able to solve or represent any computational problem, no matter how complex, given enough time and resources. In particular, that has a couple of implications:

  1. Any Turing complete language can theoretically be used to represent the logic of another Turing complete language, though the implementation may be unreasonably long.
  2. Turing complete programs can end up looping and executing forever. In fact, there is no universal way to prove that such a program will not end up running forever (otherwise known as the "halting problem").

For example, a regular calculator is not Turing complete, because it allows for only a few types of calculations. However, a computer or scientific calculator is Turing complete because any type of program can be executed on it.

Since smart contract programs can run forever, gas has become the practical way in Ethereum to manage the impact of a blockchain program! Every computation or transaction made on the blockchain costs some fees. These fees prevent expensive (or endless) contract executions, ensure miners are fairly compensated for the work they do, and provide a fair market to prioritize which transactions make it onto the blockchain.

Calculating Gas Costs

For any given program, the total gas used is calculated as the sum of the gas for each operation executed by the Ethereum Virtual Machine. For example, adding two numbers in a smart contract costs 3 gas, whereas sending a transaction costs 21,000 gas.

The total cost of gas is found by taking the amount of gas used in by a smart contract and multiplying by the gas price, a value set by you, the transaction sender.

What is Gas and How is it Used? (1)

Setting a higher gas price for your transaction means it's more likely to be confirmed on the blockchain, as the Ethereum blockchain can only confirm about 15 transactions a second. However, it also costs more Ether for the sender.

Another important value that can be set is the gas limit, or the maximum amount of gas you're willing to spend on your transaction.

By multiplying the gas price by the gas limit, you'll get the maximum amount of Ether you're allowing Ethereum to spend on gas fees for any particular transaction.

What is Gas and How is it Used? (2)

Learn about gas execution

When a smart contract call is made, the call (or transaction) will attempt to use the gas provided while the program is executed.

  • If the call succeeds, the unused gas will be returned to the sender.
  • If the call fails because it ran out of gas, the entire transaction will revert, undoing all changes to the blockchain. None of the gas will be returned, since it will all have been used up during the computation process.

A portion of gas fees from a successful transaction will be burned (or removed from the total supply) according to the new EIP-1559 spec, and the rest will be sent to the miner that added your transaction to the blockchain.

What is Gas and How is it Used? (2024)
Top Articles
Canada announces new immigration rules - Times of India
Mortgage Down Payment Information for Newcomers
Omega Pizza-Roast Beef -Seafood Middleton Menu
Automated refuse, recycling for most residences; schedule announced | Lehigh Valley Press
Woodward Avenue (M-1) - Automotive Heritage Trail - National Scenic Byway Foundation
Davita Internet
Was ist ein Crawler? | Finde es jetzt raus! | OMT-Lexikon
Tabc On The Fly Final Exam Answers
Boomerang Media Group: Quality Media Solutions
Die Windows GDI+ (Teil 1)
Carter Joseph Hopf
123 Movies Babylon
Gina's Pizza Port Charlotte Fl
Why Is Stemtox So Expensive
Craigslist Boats For Sale Seattle
My.doculivery.com/Crowncork
735 Reeds Avenue 737 & 739 Reeds Ave., Red Bluff, CA 96080 - MLS# 20240686 | CENTURY 21
2015 Honda Fit EX-L for sale - Seattle, WA - craigslist
Dr Manish Patel Mooresville Nc
Wisconsin Women's Volleyball Team Leaked Pictures
History of Osceola County
Diamond Piers Menards
The Ultimate Style Guide To Casual Dress Code For Women
V-Pay: Sicherheit, Kosten und Alternativen - BankingGeek
Caledonia - a simple love song to Scotland
Forest Biome
Masterkyngmash
Yisd Home Access Center
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Lost Pizza Nutrition
Myql Loan Login
Craigslist Ludington Michigan
Marokko houdt honderden mensen tegen die illegaal grens met Spaanse stad Ceuta wilden oversteken
Past Weather by Zip Code - Data Table
Rays Salary Cap
Craigslist Scottsdale Arizona Cars
RUB MASSAGE AUSTIN
Hair Love Salon Bradley Beach
Metro 72 Hour Extension 2022
CVS Near Me | Somersworth, NH
Page 5662 – Christianity Today
Gun Mayhem Watchdocumentaries
Flags Half Staff Today Wisconsin
Kenner And Stevens Funeral Home
Satucket Lectionary
Espn Top 300 Non Ppr
antelope valley for sale "lancaster ca" - craigslist
Roller Znen ZN50QT-E
Craigslist Com Brooklyn
Coleman Funeral Home Olive Branch Ms Obituaries
Mike De Beer Twitter
Texas 4A Baseball
Latest Posts
Article information

Author: Edwin Metz

Last Updated:

Views: 6230

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edwin Metz

Birthday: 1997-04-16

Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

Phone: +639107620957

Job: Corporate Banking Technician

Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.