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?

Alexander Herranz
  • 1,858
  • 2
  • 17
  • 35

1 Answers1

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?

Ashish kumar
  • 334
  • 1
  • 3
  • 11