Metamask Execution Rerouted: Transaction Mined, But Execution Failed
As a MetaMask user with an active wallet, you’re likely no stranger to the frustrations of interacting with decentralized applications (dApps). Recently, I experienced a similar issue on the Sepolia test net, where my deployed contract execution was reverted due to a misconfigured metamask transaction. In this article, I’ll walk you through what happened and provide a possible solution.
The Failed Transaction
Let’s assume that your contract deployment and verification on Sepolia were successful using Remix. You’ve also verified the contract on another test network or mainnet, but unfortunately, the execution of the contract was reverted due to an error in the metamask transaction.
Here are the steps involved:
- Deployed a new contract on Sepolia:
pragma Solidity version 0.8.10; import " contract MyContract is ERC20 { mapping ( address => uint256 ) public balances ; }
- Verify the contract on 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, uint256 amount) public { require(msg.value >= amount, "Transfer amount must be non-zero"); super.transfer(container, amount); } } }
- Used MetaMask on Sepolia:pragma solidity ^0.6.0 < 0.8.10; import " contract MyContractWrapper is SafeERC20 { event Transfer(address indexed recipient, uint256 indexed amount); }
- 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 Rerouted Transaction
After executing the contract, a new transaction was mined to reverse the execution of thetransferfunction. However, the metamask execution failed due to an error in the
MyContractWrappercontract.
Here's what happened:
- The contract executed thetransfer
function without any issues.
- 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 different gas limit than the one set 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.
- Verify the contract's deployment and verification again: Double-check that the contract was deployed and verified correctly on Sepolia using Remix.
- Use a different test network or mainnet: Try executing the contract on a different test network 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 with your metamask execution reverted due to an error in theMyContractWrapper` contract. If you’re still experiencing issues, feel free to provide more details, and I’ll do my best to help!