I want to execute function Tip and transfer IERC20 Token. However, this message is shown.
Uni::transferFrom: transfer amount exceeds spender allowance { "originalError": { "code": 3, "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c556e693a3a7472616e7366657246726f6d3a207472616e7366657220616d6f756e742065786365656473207370656e64657220616c6c6f77616e636500000000", "message": "execution reverted: Uni::transferFrom: transfer amount exceeds spender allowance" } }
I think I couldn't approve correctly so this error message has appeared, but I don't know how to fix... Is there are any good ideas? My code is here.
pragma solidity >=0.7.0 <0.9.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract Tip is Ownable{
address public token = 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984;
function approval (uint amount) public {
IERC20(token).approve(address(this),amount);
}
function tip (address to, uint amount) payable public {
address from = msg.sender;
IERC20(token).transferFrom(from,to,amount);
}
}