Curiosity doesn’t kill the fox. It empowers it!
If you are curious to learn more about gas and what it signifies in Ethereum, we recommend reading Basic background of blockchain and Ethereum.
A common problem that you may see or have seen is transactions failing with an out of gas error like in the screenshot below.
To avoid another "out of gas" error, you will need to increase the gas limit of your next transaction. This can be done just before sending your next transaction. For more information, please see How to Adjust Gas Price and Gas Limit?.
Advice from the MetaMask team
Selecting a gas limit is entirely up to your discretion. However, it may be helpful to review recent successful transactions of the executing smart contract to understand what is a sufficient gas limit for your transaction.
- While reviewing your transaction with the "out of gas" error on Etherscan, click the link to the Contract address in the "To:" section directly above the out of gas error
- Scroll down to the list of Transactions and click on the Txn Hash of any completed transaction (non-pending)
- Ensure that the transaction shows Status as Success. If not, go back and choose another transaction.
- Click on Click to see More
- Make a note of the Gas Limit that was chosen for the transaction
- Optional: repeat steps 1-4 to better estimate a gas limit that will be sufficient for your transaction
- Once you have a good idea of a value for your gas limit, make sure to adjust the gas limit when sending out your next transaction (see How to Adjust Gas Price and Gas Limit?)
In the example below, notice that the transaction with "Status: Fail" used up 100% of the gas.
After reviewing a different transaction for the same smart contract, we discovered that the gas limit of this transaction was set to 200,000 which was enough to complete the transaction. Notice that even though a higher gas limit was used, only 26% of it was used to complete the transaction.
While you are not required to use the same gas limit as the first successful transaction that you find, you can explore more transactions to generate an idea of what is a sufficient gas limit to ensure that your next transaction is successful.
The "out of gas" error occurs when all the gas you allotted for the transaction is consumed before the transaction could complete. During the transaction mining process, a portion of the gas is consumed for each operation that is executed on the Ethereum Virtual Machine (EVM) until the transaction is completed or until the amount of gas consumed reaches the gas limit.
The gas limit is the maximum amount of gas you are willing to spend. You can relate gas limit to putting out a fire with water from a hydrant. If you do not have a large enough water supply, you may run out of water before you can extinguish the fire. As such, you will want to ensure that you include a gas limit high enough to complete your transaction.