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?