“Out of Gas” Error: How to Fix Ethereum Network’s Failed Transactions
What does an “Out of Gas” Error Mean?
The “out of gas” error happens when all of the assigned gas limit for the transaction is used up before the network completes it. During the transaction mining process, a portion of the gas is spent for each transaction on the Ethereum Virtual Machine (EVM) until the transaction is processed or the gas limit has exceeded.
What is Gas?
As you may know, the computational work of executing transactions, including smart contracts, on the Ethereum network is measured in gas which we can also refer to, if we may, as simply the “Ethereum transaction fee”.
The gas price or gas fee is the amount of Ether you’re willing and able to pay for each unit of gas. While this is paid for in ETH, it’s measured in “Gwei” or gigawei, with 1 ETH equal to 1 billion wei – the smallest denomination of Ethereum named after Wei Dai. Are you confused by that? Don’t worry, me too! Luckily, all we need to know is that gas refers to a very tiny portion of an Ether (ETH).
The maximum quantity of gas you are willing to consume during a transaction is your gas limit. More complex transactions in the cryptocurrency world, such as those involving smart contracts, tend to have higher gas fees than a basic transaction since they demand more computational effort.
Reasons for “Out of Gas” Errors on the Ethereum Network
Generally, this kind of error message appears when conducting a smart contract operation on the Ethereum Virtual Machine (EVM); your ETH/ERC20 transaction exceeded the allocated gas limit (usually “Send” for the user).
This error is especially prevalent with ERC20 tokens, which tend to have a higher gas cost than normal ETH (Ethereum).
Other reasons for this can be:
- The amount of gas provided for the transaction is insufficient to cover the amount required to complete the transaction.
- In smart contract programming, there is an infinite loop or another unbounded processing issue.
- The contract was not created with the correct Ethereum Virtual Machine version.
- The amount of Ether/Ethereum in the from account is insufficient to complete the transaction.
- The contract has been reversed or reverted.
How to Fix an “Out of Gas” Error? Increase Your Gas Limit for an Ethereum Transaction!
Essentially, you’ll need to increase the gas limit of your next transaction to avoid another “out of gas” error. As a rule of thumb, I double the amount that was previously set as the limit – this is by no means the only way to increase your limits, and there are websites specifically for calculating gas prices, if you’d prefer – I just like quick and easy fixes! Either way, you’ll want to ensure you set a higher gas limit in your wallet app’s settings to ensure future transactions are completed the first time.
Don’t worry about making the limit too high as the transaction only consumes what is required to complete it and no more. Conversely, if you set the gas limit too low, you’ll end up with the “out of gas” error and, because this refers to the portion of the total fee that is burned (used up), it won’t be refunded to you because it has been used up trying to complete your transaction.
Usually, a wallet app’s default gas limit (often 21,000 or higher) is set at a high enough limit for all transactions to go through. However, there are always exceptions to the rule, such as smart contracts previously mentioned.
If you want to deep dive into gas fees and how they now work since the London Hard Fork in August 2021, I recommend this article by ETH Gas Station.
Common Terms Used with ETH Gas
Base Fee (baseFeePerGas) – is the minimum price per unit of gas for an Ethereum transaction to be included in a block. The network calculates the base fee subject to the network’s demand (how “busy” it is) and the previous block sizes. The base fee is the portion of the total transaction fee you pay that is burned (used up) by the network.
Gas Fee – refers to the total transaction fee users pay on the Ethereum network for a transaction to be included in the next block.
Gas Limit – the maximum amount of gas you’re willing to have consumed for a transaction to be processed. A typical transaction uses 21,000 Gwei.
Max Fee (maxFeePerGas) – is the maximum amount paid for your transaction to be included in a block. This amount is made up of the base cost plus the priority fee. Any excess between what’s needed to complete the transaction and your set Max Fee is refunded to you. You set this limit (or your wallet app if using the default).
Priority Fee – also called the “miner’s tip”, is a payment made to the miners/validators for them expediting your transaction. This portion of the total transaction fee was introduced in the London upgrade. A higher tip means your transaction is likely to be processed faster. To learn more, check out the calculator mentioned in the resources below.
For a very detailed look at what gas is and how it is calculated: https://ethereum.org/en/developers/docs/gas/
Historical Average ETH Gas Prices: https://ycharts.com/indicators/ethereum_average_gas_price
Gas Price Calculator: https://legacy.ethgasstation.info/index.php