I can not transfer ERC20 tokens from my address to the contract. But I can transfer from the contract to other addresses.
my account(msg.sender) has 10 link(ERC20) tokens . and i want to send these tokens to contract
i am using remix and rinkeby network - metamask this is my code
// SPDX-License-Identifier: GPL-3.
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract TransferTokens {
function transferToMe(address _token, uint _amount) public {
//token is chainlink_ERC20 address
//i have links in mo account
IERC20(_token).transferFrom(msg.sender, address(this), _amount);
}
}
the error is The transaction execution will likely fail
transferFromfunction, you're doing so on behalf of themsg.sender. This action needs to have prior approval usingapproveorincreaseAllowancefunction as defined in: https://docs.openzeppelin.com/contracts/4.x/api/token/erc20#ERC20-approve-address-uint256- – Stanislav Svědiroh Feb 18 '22 at 18:38transferToMefunction is called externally (wallet or a different contract) hencemsg.senderis notTransferTokens. As far as I understood the question, this function works. The thing OP needs to accomplish is to successfully send tokens TO this smart contract. – Stanislav Svědiroh Feb 19 '22 at 09:55