0

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]

Even if I try to set amount to zero.

Help me please.

1

3 Answers 3

4

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.

1

ethereum usdt:

function approve(address spender, uint value) public;

ethereum IERC20:

function approve(address spender, uint256 amount) external returns (bool);

So,using IERC20's approve will return the result, but USDT's approve will not return the data. If you call the approve function of USDT contract T to force the data to be returned, it will revert.

-1

The error you are encountering during contract execution is likely due to the fact that the USDT token on the Ethereum network uses a different contract address and/or ABI than the USDT token on the Polygon network. This means that the IERC20 interface may not be compatible with the USDT token on the Ethereum network, which could be causing the approve function to fail. To resolve this issue, you may need to update the contract to use the correct contract address and ABI for the USDT token on the Ethereum network. You can find the contract address and ABI for the USDT token on the Ethereum network by searching for it on a blockchain explorer like Etherscan. Once you have the correct contract address and ABI, you can update the contract to use them by replacing the IERC20 interface with the correct interface for the USDT token on the Ethereum network. You may also need to update the adminApprove function to use the correct contract address for the USDT token on the Ethereum network. Here is an example of how you could update the contract to use the correct contract address and ABI for the USDT token on the Ethereum network:

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 
    {
        // Replace the IERC20 interface with the correct interface for the USDT token on the Ethereum network
        IERC20 usdt = IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7);
        
        // Use the correct contract address for the USDT token on the Ethereum network
        usdt.approve(spender, amount);
    }
}

Note that you will need to replace the contract address and ABI in the example above with the correct values for the USDT token on the Ethereum network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.