Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Approve USDT on Ethereum

I have a very simple contract.

contract MyContract {
    
    address _owner;

    modifier owner() {
        require(msg.sender == _owner);
        _;
    }

    constructor(address manager) {
        _owner = manager;
    }

    function adminApprove(address token, uint256 amount, address spender) external owner 
    {
        IERC20(token).approve(spender, amount);
    }
}

Function adminApprove works fine for USDT and USDC on POLYGON network and works fine for USDC on ETHEREUM network, but not works for USDT on ETHEREUM network.

Error encountered during contract execution [execution reverted]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Even if I try to set amount to zero.

Help me please.

>Solution :

The USDT contract on ethereum doesn’t implement the IERC20 interface correctly. Namely, functions that are supposed to return a bool (like approve does) don’t. Since you’re using the standard IERC20 interface, your contract is looking for that return value, can’t find it, and reverts. Update your interface or use something like openzeppelin’s SafeERC20, which supports both cases.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading