0

I'm developing a Smart Contract that transfer tokens that are owned by the Smart Contract itself. The function to do that is pretty simple:

pragma solidity 0.8.1;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract TransferTokens {

    IERC20 token;

    constructor(){
        token = IERC20(0x...);
    }

    function sendTokens(address receiver, uint256 amount) external {
        token.transfer(receiver, amount);
    }
}

And I'm getting: execution reverted: ERC20: insufficient allowance

I have deployed my own token, which is an Openzeppelin ERC20 contract. That revocation happens in _spendAllowance function, which is invoked in transferFrom function, not in transfer function.

How can it be possible to get an error (from transferFrom function) that should not be thrown in my function (transfer function)?

How could I make my contract able to send the received ERC20 tokens, after a function execution?

7

1 Answer 1

0

Have you checked balanceOf() with address of smart contract? Does it show any balance? Also, I don't understand why are you writing

IERC20 token = IERC20(tokenAddress);

You have already instantiatiated token in constructor. And what 'tokenAddress' are you passing?

1
  • Yes sure, the contract had the received balance. And you are right, that line of code was redundant, already instantiated. Jun 26, 2022 at 18:55

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.