🛠️ We partnered with Alchemy to bring you a FREE Ethereum Developer Bootcamp! Get started here 🛠️
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:
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:
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.
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.
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.
“Wei” is the smallest unit of Ether, where 10¹⁸ Wei represents 1 Ether. One gwei is 10⁹ wei, and there are 10⁹ gwei per Ether.
When a smart contract call is made, the call (or transaction) will attempt to use the gas provided while the program is executed.
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.
Prior to the implementation of Ethereum proposal EIP-1559 on August 5, 2021, transactions were included on to the blockchain using a first-price gas auction. Whi