LINK.transferFrom() function dosent work after approval?

:computer: Environment

I'm using REMIX Online IDE.

:memo:Details

I'm trying to transfer tokens from a LINK erc20 wallet (Connected via Metamask) to my contracts address.
The approveTransfer functions goes in without an issue, however when i call the transferToken function i keep running into "reverted" error.

I did verify that i have enough balance in my link token address before trying to send.
At this point i'm not sure what i did wrong.

Would appreciate all the help i can get :slight_smile: <3 regards Dan.

:1234: Code to reproduce

address linkAdr = 0x84b9B910527Ad5C03A9Ca831909E21e236EA7b06;
IERC20 link = IERC20(linkAdr);
uint256 public userlinkbalance = 0;
address public msgSender = _msgSender();
uint256 public approvedAmount = 0;
function transferToken(uint256 amount) external returns(string memory){
    uint256 linkAmt = amount * 10**18;
    link.transferFrom(_msgSender(), address(this), linkAmt);
}
function approveTransfer(uint256 amount) external returns(string memory) {
    uint256 approveAmt = amount * 10**18;
    userlinkbalance = link.balanceOf(_msgSender());
    link.approve(address(this),approveAmt);
    approvedAmount = approveAmt;
}

function getLinkBalance() public view returns(uint256){
    return link.balanceOf(address(this));
}

Hey, welcome! :wave:

I think you should call approve directly, that is calling the approve in the link token rather than in your contract.
The right steps should be:

  • link.approve(address(YOUR_CONTRACT),approveAmt);
  • Call transferToken() in your contract