I have created a contract which is a ERC20 contract. Once the contract is created, I have specified some amount of ERC20 tokens to be minted and sent to the contract.

Moreover, I have defined that whenever someone sends funds to the contract, should be paid by some amount of tokens in proportion to the entered fund.

However, every time I try to send some amount of ethers to the contract in return for tokens, I am given this error: "Transfer amount exceeds allowance".

I guess it might be related to the Approve() or increaseAllowance() function of ERC20, but I am not sure. Does anyone know what should I do prior to the Transfer(), and discuss the difference between these two for me?

While intending to send Tokens, which are minted and kept in a contract, to an address which one should we use Transfer() or transferFrom() ?

  • 1
    Can you show the code used? Who owns the tokens being transferred? If the tokens are owned by the contract then transfer should be used. If the tokens are owned by another account transferFrom has to be used, the owner account must had approved the contract to send the tokens.
    – Ismael
    Oct 9 at 17:37