Ethereum Gas is the lifeblood of the Ethereum ecosystem, there is no other way of putting that. Gas is a unit that measures the amount of computational effort that it will take to execute certain operations.
Every single operation that takes part in Ethereum, be it a simple transaction, or a smart contract, or even an ICO takes some amount of gas. Gas is what is used to calculate the amount of fees that need to be paid to the network in order to execute an operation.
In this guide, we are going to understand how gas works. But before we do so, there are several concepts that we must learn. So, without further ado, lets begin our deep dive on Ethereum Gas.
Bitcoin was created because everyone was asking the same questions.
Satoshi Nakamoto answered these questions when he created bitcoin. We finally had a decentralized monetary system which can transfer money from one person to another.
However, there was a problem with bitcoin which is a problem with all first generation blockchains. They only allowed for monetary transactions, there was no way to add conditions to those transactions.
Alice can send Bob 5 BTC, but she couldnt impose conditions on those transactions. Eg. She couldnt tell Bob that he will get the money only if he performed certain tasks.
These conditions would need extremely complicated scripting. Something was required to make the process more seamless.
And that something was a smart contract.
Smart contracts help you exchange money, property, shares, or anything of value in a transparent, conflict-free way while avoiding the services of a middleman.
Vitalik Buterins Ethereum is easily the stalwart of this generation. They showed the world how the blockchain can evolve from a simple payment mechanism to something far more meaningful and powerful.
So, what are these smart contracts and whats the big deal?
Smart contracts are automated contracts. They are self-executing with specific instructions written in its code which get executed when certain conditions are made.
You can learn more about smart contracts in our in-depth guide here.
Smart contracts are how things get done in the Ethereum ecosystem. When someone wants to get a particular task done in Ethereum they initiate a smart contract with one or more people.
Smart contracts are a series of instructions, written using the programming language solidity, which works on the basis of the IFTTT logic aka the IF-THIS-THEN-THAT logic. Basically, if the first set of instructions are done then execute the next function and after that the next and keep on repeating until you reach the end of the contract.
The best way to understand that is by imagining a vending machine. Each and every step that you take acts like a trigger for the next step to execute itself. It is kinda like the domino effect. So, lets examine the steps that you will take while interacting with the vending machine:
Now look at all those steps and think about it. Will any of the steps work if the previous one wasnt executed? Each and every one of those steps is directly related to the previous step. There is one more factor to think about, and it is an integral part of smart contracts. You see, in your entire interaction with the vending machine, you (the requestor) were solely working with the machine (the provider). There were absolutely no third parties involved.
So, now how would this transaction have looked like if it happened in the Ethereum network?
Suppose you just bought something from a vending machine in the Ethereum network, how will the steps look like then?
Every transaction that you do through the smart contracts will get recorded and updated by the network. What this does is that it keeps everyone involved with the contract accountable for their actions. It takes away human malice by making every action taken visible to the entire network
Before we understand what the Ethereum Virtual Machine (EVM) is, we must understand why a Virtual Machine is needed.
So lets go back to smart contracts.
What are the desirable properties that we want in our smart contract?
Anything that runs on a blockchain needs to be immutable and must have the ability to run through multiple nodes without compromising on its integrity. As a result of which, smart contract functionality needs to be three things:
A program is deterministic if it gives the same output to a given input every single time. Eg. If 3+1 = 4 then 3+1 will ALWAYS be 4 (assuming the same base). So when a program gives the same output to the same set of inputs in different computers, the program is called deterministic.
There are various moments when a program can act in an un-deterministic manner:
In mathematical logic, we have an error called halting problem. Basically, it states that there is an inability to know whether or not a given program can execute its function in a time limit. In 1936, Alan Turing deduced, using Cantors Diagonal Problem, that there is no way to know whether a given program can finish in a time limit or not.
This is obviously a problem with smart contracts because, contracts by definition, must be capable of termination in a given time limit. There are some measures taken to ensure that there is a way to externally kill the contract and to not enter into an endless loop which will drain resources:
In a blockchain, anyone and everyone can upload a smart contract. However, because of this the contracts may, knowingly and unknowingly contain virus and bugs.
If the contract is not isolated, this may hamper the whole system. Hence, it is critical for a contract to be kept isolated in a sandbox to save the entire ecosystem from any negative effects.
Now that we have seen these features, it is important to know how they are executed. Usually, the smart contracts are run using one of the two systems:
Lets compare these two and determine which makes for a better ecosystem. For simplicitys sake, we are going to compare Ethereum (Virtual Machine) to Fabric (Docker).
So, as can be seen, Virtual Machines provide better Deterministic, terminable and isolated environment for the Smart contracts. However, dockers have one distinct advantage. They provide coding language flexibility while in a Virtual Machine (VM) like Ethereum, one needs to learn a whole new language (solidity) to create smart contracts.
The EVM is the virtual machine in which all the smart contracts function in Ethereum. It is a simple yet powerful Turing Complete 256-bit virtual machine. Turing Complete means that given the resources and memory, any program executed in the EVM can solve any problem.
As explained in the introduction, Gas is a unit that measures the amount of computational effort that it will take to execute certain operations.
Note: Before we continue, huge shoutout to Joseph Chow for his amazing presentation on Ethereum gas.
Most of the smart contracts that run in the EVM are coded using Solidity (Ethereum is planning to move on to Viper from Solidity in the future). Each and every line of code in Solidity requires a certain amount of gas to be executed.
The image below has been taken from the Ethereum Yellowpaper and can be used to gain a rough idea of how much specific instructions cost gas-wise. Every transaction requires at least 21,000 gas according to this table:
Image Courtesy: Ethereum Yellow Paper
To better understand how gas works in Ethereum, lets use an analogy. Suppose you are going on a road trip. Before you do so you go through these steps:
Now, lets draw parallels with Ethereum.
Driving the car is the operation that you want to execute, like executing a function of a smart contract.
The gas is well.gas.
The gas station is your miner.
The money that you paid them is the miner fees.
All the operations that users want to execute in ethereum must provide gas for the following:
Now that we have covered the bare basics, you maybe asking the following question.
The answer is simpleincentivization.
Like any proof-of-work peer-to-peer system, Ethereum is heavily dependent on the hashrate of their miners. More the miners, more the hashrate, more secure and fast the system.
In order to attract more miners into the system, they need to make the system as profitable and alluring as possible for the miners. In Ethereum, there are two ways that miners can earn money:
Lets explore the second point.
The miners are responsible for putting transactions inside their blocks. In order to do so, they must use their computational power to validate smart contracts. The gas system allows them to charge a certain fee for doing so.
This fee is known as the miners fee and it helps incentivize them enough to take part actively in the ecosystem.
So, how much fees can they charge? Before we can calculate that lets understand how we measure gas.
Gas is simply measured in units of gas. A transaction sent to the Ethereum network costs some discrete amount of gas (e.g. 100 gas) depending on how many EVM instructions need to be executed.
More here:
What is Ethereum Gas: Step-By-Step Guide - Blockgeeks
- How does Ethereum work - Medium [Last Updated On: February 3rd, 2018] [Originally Added On: February 3rd, 2018]
- Ethereum - BTCMANAGER [Last Updated On: February 19th, 2018] [Originally Added On: February 19th, 2018]
- This Giant Infographic Compares Bitcoin, Ethereum, and ... [Last Updated On: February 19th, 2018] [Originally Added On: February 19th, 2018]
- What is Ethereum? | CryptoCompare.com [Last Updated On: February 23rd, 2018] [Originally Added On: February 23rd, 2018]
- The Top 10 Best Ethereum Wallets (2018 Edition) [Last Updated On: February 23rd, 2018] [Originally Added On: February 23rd, 2018]
- Ethereum fixes serious eclipse flaw that could be exploited ... [Last Updated On: March 7th, 2018] [Originally Added On: March 7th, 2018]
- How does Ethereum work, anyway? - Medium [Last Updated On: April 25th, 2018] [Originally Added On: April 25th, 2018]
- Free-Ethereum.com - Free Ether! [Last Updated On: May 31st, 2018] [Originally Added On: May 31st, 2018]
- What is Ethereum? | The Ultimate Beginners' Guide [Last Updated On: June 20th, 2018] [Originally Added On: June 20th, 2018]
- Ethereum Mining Guide for AMD and NVidia GPUs - Windows ... [Last Updated On: June 20th, 2018] [Originally Added On: June 20th, 2018]
- Ethereum: Blockchains, Digital Assets, Smart Contracts ... [Last Updated On: July 16th, 2018] [Originally Added On: July 16th, 2018]
- Ethereum Price - Mobile Friendly Price of Ether [Last Updated On: July 16th, 2018] [Originally Added On: July 16th, 2018]
- Ethereum Soars with over a 2,800% Rally - Coin News Asia [Last Updated On: July 28th, 2018] [Originally Added On: July 28th, 2018]
- Ethereum Co-Founder Joseph Lubin Says Speculators Driving ... [Last Updated On: August 20th, 2018] [Originally Added On: August 20th, 2018]
- Bitcoin and Ethereum: A Look At The Week Ahead [Last Updated On: September 2nd, 2018] [Originally Added On: September 2nd, 2018]
- EthereumPrice - Official Site [Last Updated On: October 3rd, 2018] [Originally Added On: October 3rd, 2018]
- Ethereum Classic Price Analysis: ETC/USD Could Revisit $12 [Last Updated On: October 6th, 2018] [Originally Added On: October 6th, 2018]
- Ethplorer Ethereum tokens explorer and data viewer. Top ... [Last Updated On: October 6th, 2018] [Originally Added On: October 6th, 2018]
- Buy and Sell Ether With The Peer-to-Peer Ethereum ... [Last Updated On: October 6th, 2018] [Originally Added On: October 6th, 2018]
- Ethereum Price - CoinDesk [Last Updated On: October 18th, 2018] [Originally Added On: October 18th, 2018]
- EthereumPrice.org - USD Price, Charts & History [Last Updated On: October 18th, 2018] [Originally Added On: October 18th, 2018]
- Report: Whales Accumulate Ethereum (ETH) En-Masse Amid Bear ... [Last Updated On: December 7th, 2018] [Originally Added On: December 7th, 2018]
- GitHub - ethereum/go-ethereum: Official Go implementation of ... [Last Updated On: December 7th, 2018] [Originally Added On: December 7th, 2018]
- Ethererum Crypto-Economics Index Real-time Price Charts and ... [Last Updated On: December 7th, 2018] [Originally Added On: December 7th, 2018]
- Ethereum Definition | Investopedia [Last Updated On: December 7th, 2018] [Originally Added On: December 7th, 2018]
- Ethereum Price Analysis: ETH Could Extend Losses Below $80 ... [Last Updated On: December 19th, 2018] [Originally Added On: December 19th, 2018]
- Ethereum Price Analysis: ETH Could Turn Bullish Above $90 ... [Last Updated On: December 19th, 2018] [Originally Added On: December 19th, 2018]
- Bitcoin, Ethereum, Ripple Prices Surge Higher; FOMO Santa Rally? [Last Updated On: December 26th, 2018] [Originally Added On: December 26th, 2018]
- Ethereum Co-Founder Calls the Cryptobottom of 2018 ... [Last Updated On: December 26th, 2018] [Originally Added On: December 26th, 2018]
- Part 1: Ethereum vs NEO Which blockchain will provide ... [Last Updated On: December 31st, 2018] [Originally Added On: December 31st, 2018]
- Ethereum Price Analysis: ETH Corrects Sharply, Can It Hold ... [Last Updated On: December 31st, 2018] [Originally Added On: December 31st, 2018]
- Ethereum: JPMorgan, Microsoft, Banks Form ... - fortune.com [Last Updated On: January 3rd, 2019] [Originally Added On: January 3rd, 2019]
- Ethereum News | Ethereum News today | Latest Ethereum News [Last Updated On: January 3rd, 2019] [Originally Added On: January 3rd, 2019]
- Ethereum (ETH) - Price, Chart, Info | CryptoSlate [Last Updated On: January 3rd, 2019] [Originally Added On: January 3rd, 2019]
- Ethereum Cash Pro [Last Updated On: January 3rd, 2019] [Originally Added On: January 3rd, 2019]
- What Is Ethereum? Here's What You Need To Know [Last Updated On: January 3rd, 2019] [Originally Added On: January 3rd, 2019]
- What is Ethereum? | The Ultimate Beginners Guide [Last Updated On: January 27th, 2019] [Originally Added On: January 27th, 2019]
- Ethereum Classic - A smarter blockchain that takes digital ... [Last Updated On: January 27th, 2019] [Originally Added On: January 27th, 2019]
- Ethereum Price Analysis: ETH Relatively Muted, Next Move ... [Last Updated On: January 27th, 2019] [Originally Added On: January 27th, 2019]
- Buy and Sell Ether With The Peer-to-Peer Ethereum Marketplace ... [Last Updated On: January 27th, 2019] [Originally Added On: January 27th, 2019]
- What is Ethereum? | The Ultimate Beginners' Guide - CoinCentral [Last Updated On: January 30th, 2019] [Originally Added On: January 30th, 2019]
- Ethereum Price Analysis: ETH Breaks Down, Turned Sell on ... [Last Updated On: January 30th, 2019] [Originally Added On: January 30th, 2019]
- Ethereum Price Analysis: ETH Remains Sell Near $128 ... [Last Updated On: March 6th, 2019] [Originally Added On: March 6th, 2019]
- Ethereum Price Analysis: ETH Remains Sell Near $128, Target ... [Last Updated On: March 11th, 2019] [Originally Added On: March 11th, 2019]
- Create a cryptocurrency contract in Ethereum [Last Updated On: March 11th, 2019] [Originally Added On: March 11th, 2019]
- Ethereum Price Analysis: ETH Buyers Wont Give Up Easily ... [Last Updated On: March 11th, 2019] [Originally Added On: March 11th, 2019]
- Buy and Sell ETH With The Peer-to-Peer Ethereum Marketplace ... [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum Technical Analysis - FXStreet [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum - Investopedia [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum - reddit [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum vs Bitcoin: The Battle for the Crypto Throne - Coindoo [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum Price Analysis: ETH Could Make a Sustained Move ... [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum Project [Last Updated On: March 18th, 2019] [Originally Added On: March 18th, 2019]
- Ethereum - Official Site [Last Updated On: April 20th, 2019] [Originally Added On: April 20th, 2019]
- Ethereum (ETH) Price Starts Much Awaited Rebound To $170 [Last Updated On: May 9th, 2019] [Originally Added On: May 9th, 2019]
- Ethereum Price Analysis: ETH Corrects But More Upsides Likely ... [Last Updated On: May 9th, 2019] [Originally Added On: May 9th, 2019]
- Ethereum Price Analysis: ETH Primed For Additional Losses ... [Last Updated On: May 9th, 2019] [Originally Added On: May 9th, 2019]
- Ethereum Won't Fail: Joseph Lubin - ccn.com [Last Updated On: May 9th, 2019] [Originally Added On: May 9th, 2019]
- Ethereum (ETH) Price Starts Fresh Increase: Bitcoin Leading ... [Last Updated On: May 9th, 2019] [Originally Added On: May 9th, 2019]
- Bitcoin Booming As Ethereum, Ripple's XRP, EOS And Litecoin ... [Last Updated On: May 9th, 2019] [Originally Added On: May 9th, 2019]
- Ethereum Bounty Program [Last Updated On: May 30th, 2019] [Originally Added On: May 30th, 2019]
- Dark Horses of dApps: 6 Blockchains With Ethereum In Their Sights - Crypto Briefing [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- Latin Americans get two new ways to trade Bitcoin, Ethereum, and more - Decrypt [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- Ethereums Bearish Wave Count Outlined by Cryptocurrency Analyst - BeInCrypto [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- XRPs Third Quarter Inflation Rate Was Lower Than Ethereum (ETH) and Litecoin (LTC) - SludgeFeed [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- Ethereum (ETH) Dives To $170, Is $160 Next Bear Target? - newsBTC [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- Thomson Reuters: Bringing Smart Contracts to the Mainstream With Ethereum & Chainlink - Blockonomi [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- Crypto Analyst: Ethereum Has Bottomed, Expected To See Extended Rally - newsBTC [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- WATCH: MyCrypto CEO Taylor Monahan on Crypto Adoption and Ethereum - Coindesk [Last Updated On: October 21st, 2019] [Originally Added On: October 21st, 2019]
- Cryptocurrency market update: Kicks of a dying horse as Bitcoin, Ethereum and Ripple remain suppressed - FXStreet [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Cryptocurrencies price prediction: Bitcoin, Ethereum & Litecoin - American Wrap - 22 October - FXStreet [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Ethereums gas prices show an unusual surge when the Asian market sleeps - AMBCrypto [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Whale Consolidates $88M Worth of Ethereum in Two Transactions - BeInCrypto [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Ethereum Falls 10% In Selloff - Yahoo Finance [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- TRON Joins Bitcoin And Ethereum On Opera Browser - Crypto Briefing [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Ethereum (ETH) Rebound Faces Major Hurdle Near $180 - newsBTC [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Ethereum Breakout Above $360 Means Skys the Limit, Believes Cryptocurrency Analyst - BeInCrypto [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Ethereum Futures: The Next Big Derivative to Hit the Market? - Cointelegraph [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Ethereum and Stellars Lumen Daily Tech Analysis 23/10/19 - Yahoo Finance [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]
- Why Bear Market Ethereum Futures Are a Better Bet That Bitcoins - newsBTC [Last Updated On: October 24th, 2019] [Originally Added On: October 24th, 2019]