0

0

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);
    }
}

I executed approve() out of Tip Contracts like this.

 function approval (uint amount) public {
        address spender = 0x5c366635c0343B00eDdE51263D6E580Adb9052D5;
        IERC20(token).approve(spender,amount);
    }

Then, back to the Tip Contract and execute tip(). However the same error message is shown yet.

Where is the mistake in what I have done?

1
  • That's the user who has to call the approve function on the ERC20 smart contract, not a smart contract.
    – clement
    Jul 4 at 14:55

Browse other questions tagged or ask your own question.