MetaMask Execution Redirected: Transaction Retrieved, but Execution Failed
As a MetaMask user with an active wallet, you are probably no stranger to the frustration of interacting with decentralized applications (dApps). I recently encountered a similar issue on the Sepolia testnet, where my deployed contract execution was rolled back due to a misconfigured metamask transaction. In this article, I will explain what happened and offer a possible solution.
The Failed Transaction
Let’s assume that your contract deployment and Sepolia verification are successful using Remix. You have also verified the contract on another testnet or mainnet, but unfortunately the contract execution rolled back due to an error in the metamask transaction.
Here are the steps involved:
- Deploy a new Sepolia contract:
pragma Solidity version 0.8.10; import " contract MyContract is ERC20 { mapping (address => uint256) public balances; }
- Checked the contract for Sepolia:
pragma solidity ^0.6.0 < 0.8.10; import " import " contract MyContractWrapper is SafeERC20 { constructor() public { address _owner = msg.sender; } function transfer(recipient address, amount uint256) public { require(msg.value >= amount, "Transfer amount must be non-zero"); super.transfer(recipient, amount); }}
- Used MetaMask on Sepolia:pragma solidity ^0.6.0 < 0.8.10; import " contract MyContractWrapper is SafeERC20 { event Transfer(recipient with indexed address, indexed amount uint256); }
- I executed the contract using MetaMask:pragma solidity ^0.6.0 < 0.8.10; import " import " contract MyContractWrapper is SafeERC20 { function () public payable { balances [msg.sender] += 10; } }
The Redirected Transaction
After the contract was executed, a new transaction was mined to return the execution of thetransferfunction. However, the execution of the metamask failed due to an error in the
MyContractWrappercontract.
Here's what happened:
- The contract executed thetransfer
function without any problems.
- A new transaction was mined using MetaMask, which attempted to transfer 10 units from the wallet address that owns the contract.
- However, the metamask execution failed due to an error in theMyContractWrapper
contract, specifically because it tried to send the transaction with a gas limit different from the one specified in the contract.
Possible solution
To prevent similar issues in the future, you can try the following:
- Check your metamask settings: Make sure that MetaMask is set to use the correct gas limit for transactions.
- Check the contract deployment and verification again: Double-check that the contract was deployed and verified correctly on Sepolia using Remix.
- Use a different testnet or mainnet: Try executing the contract on a different testnet or mainnet to see if the issue is specific to one of them.
By following these steps, you should be able to resolve the issue of your metamask execution rolling back due to an error in theMyContractWrapper` contract. If you are still having trouble, feel free to provide more details and I will do my best to help!