Lỗi warning error encountered during contract execution out of gas

Within the domain of Web3 development, engineers regularly face unique obstacles, one of them being the daunting error message: “Warning! Error encountered during contract execution [execution reverted].” This message often leaves developers perplexed, but understanding its roots can provide insightful answers for troubleshooting. This blog aims to demystify this error message, exploring its possible triggers, and provides strategies for resolving it.

Lỗi warning error encountered during contract execution out of gas

🤯 What is an “Execution Reverted” Error?

An execution reverted error is one of possible runtime errors. This error represents a transaction that was unable to execute due to an unmet condition in the contract. In other words, the Ethereum Virtual Machine (EVM) — the processor that enables smart contracts to run — restores the state to its previous condition before the transaction attempt. Consequently, even though no changes were made, the person trying to transact still loses the gas consumed in the transaction.

Unraveling the Cause of Execution Reverted

Developers deliberately incorporate checks in the smart contract to reject invalid transactions. The “execution reverted” error emerges when a transaction contradicts the contract’s stipulated business logic. For instance, a contract may specify the Ether amount necessary for its execution. Any deviation from this amount will lead to a halted transaction, representing an error from the transaction sender’s perspective. However, from the contract’s viewpoint, this is a legitimate response to an invalid transaction.

The smart contract developer can implement any kind of requirement statement, some examples are (1) only whitelisted addresses to call a function (2) limitation on how often a function can be called in a specific block period (3) the wallet trying to execute a function must have a specific holding/characteristic (4) functions only to be called by the contract owner.

When the require statement does not include an error message (=> a string that represents the reason) or imcludes a very encrypted error message, then understanding the logic is definitely much harder.

Example of require statement in Uniswap V3 SwapRouter contractExample of require statement in Bored Ape Yacht Club smart contract

Strategies for Error Resolution

Addressing “Execution Reverted” errors requires thorough analysis and precise debugging:

  1. Review Contract Logic: Begin by thoroughly checking your smart contract’s code for any logical inconsistencies or unfulfilled conditions during execution.
  2. Improve Error Messaging: Consider customizing error messages in your require() functions. This can aid in pinpointing issues causing contract failures more accurately.
  3. Thorough Testing: Conduct extensive tests of your contracts to identify potential problems before deploying on the mainnet. Use automated testing to cover diverse scenarios and ensure your contracts function as expected.

Conclusion

The “Warning! Error encountered during contract execution [execution reverted]” error is a frequent challenge in web3 engineering. To successfully navigate this terrain, understanding the root causes of this error and mastering the debugging methods are essential. A well-tested and understood smart contract is your best defense against these pitfalls. As the landscape of Web3 development continues to evolve, our ability to overcome these challenges is vital to building robust and efficient blockchain solutions.

At Blocktorch we are on a mission to give web3 builders superpowers. Our web3 observability platform provides end-2-end observability like real-time tracing, logging and monitoring for developers building decentralized applications and smart contracts. We support the full stack of any dApp.

This usually means that the amount of gas specified in MetaMask is too low to run the instructions required by the EOS claimAll() function in the smart contract. Not only will the transaction fail, but you could also find yourself burning through a significant amount of ether in the process.

Fortunately, the fix is rather trivial. Simply set your gas limit to 5000000, and reduce the gas price to only 2 Gwei. This gas price will take a few minutes longer, but will save you a lot of ether in Tx fees.

If you see that error, it means the gas limit you set was above the minimum but still not sufficient to get the transaction through. Please try again with a higher gas limit.

It might also help to look back at your previous successful transactions and see what gas limit was set for them.

Still not quite what you were looking for? We’ll be happy to help! Please, include your EOS/WAX/Telos account name or the Ethereum address, the device you’re using Wombat on, Wombat version (you can see it in the lower section of Settings), as well as your sign-up method (Gmail, Facebook, Twitter or Apple ID) and details of the issue you’re facing. Our Support Team will get back to you within 48 hours.