I am trying to develop a buy function for my token smart contract, but it fails on the transfer:

transfer(msg.sender, amountToBuy);

It fails with the Error: 'ERC20: transfer amount exceeds balance', even though the contract has enough tokens in its balance: Enough Tokens in balance, 400k to be exact.

  • Can you give more details? Is the contract sending the tokens the ERC20 contract? Can you supply a sample code that reproduces the error?
    – Ismael
    Commented Sep 2, 2021 at 5:24

1 Answer 1


Ok I found the Answer. Instead of just doing transfer in the code, I create an object out of the IERC20 Interface.

This is needed for a smart contract to transfer its own tokens:

IERC20(this).transfer(msg.sender, amountToBuy);

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.