2

I’m trying to return the balance of msg.sender from an external contract, but when I try to compare pair.balanceOf() to an uint256, it tells me they are not comparable.

I’m using Solidity 0.8.0 on Remix with OpenZeppelin contracts.

interface TokenInterface {
    function balanceOf(address account) view external;
}

contract Contract {
    address public tokenAddress = 0xc5d63121bA479BAeb666a896e84283a1a0AefAe6;

    TokenInterface token = TokenInterface(tokenAddress);

    function stake(uint256 amount) public {
        require(token.balanceOf(msg.sender) >= amount, "Insufficient balance.");

        ...

    }
}

The other contract is an ERC20 built with OpenZeppelin.

Thanks and have a nice day :)

1 Answer 1

1

This is because function balanceOf() in your interface is not returning any value, so the require in function stake() can't compare balance with amount.

You need to update the interface to return the balance:

interface TokenInterface {
    function balanceOf(address account) view external returns(uint256);
}
0

Your Answer

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

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