When checking if the number of tokens is greater or equal to in the smart contract it self it gives me this error;

TypeError: Invalid type for argument in function call. Invalid

See code below:

contract MarbCoinSale {

    address admin;

    MarbCoin public tokenContract;

    uint256 public tokenPrice;
    uint256 public tokensSold;

    event Sell(address _buyer, uint256 _amount);

    constructor (MarbCoin _tokenContract, uint256 _tokenPrice) public {
        admin = msg.sender;
        tokenContract = _tokenContract;
        tokenPrice = _tokenPrice;

    function multiply(uint x, uint y) internal pure returns (uint z) {
        require(y == 0 || (z = x * y) / y == x);

    function buyTokens (uint256 _numberOfTokens) public payable {

        require(msg.value == multiply(_numberOfTokens, tokenPrice));

        require(tokenContract.balanceOf(this) >= _numberOfTokens);

        tokensSold += _numberOfTokens;

        emit Sell(msg.sender, _numberOfTokens);
  • Do you want to know the balance of an ERC20 token? or the ETH balance?
    – jeissoni22
    Commented Feb 4, 2022 at 16:34
  • I want to know the balance of an ERC20 token Commented Feb 6, 2022 at 8:29


Browse other questions tagged or ask your own question.