function approveOtherContract(IERC20 _token, address recipient) public returns(bool){
return _token.approve(recipient, 1e18);
}
function tokenTransfer(address _token, uint _amount) public {
//IERC20(_token).approve(_contract,_amount);
IERC20(_token).transferFrom(msg.sender, address(this), _amount);
newTokens.push(_token);
}
function getBalanceOfToken(address _address) public view returns (uint) {
return IERC20(_address).balanceOf(address(this));
}
I approved contract using function approveOtherContract ,but at time of tokentransfer it does not work and gives error - Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
execution reverted: ERC20: transfer amount exceeds allowance { "originalError": { "code": 3, "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002845524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365000000000000000000000000000000000000000000000000", "message": "execution reverted: ERC20: transfer amount exceeds allowance" } }
Thanks for your reply @FreezyEx.
Now I understand.
So we have to do it using web3(can I get example) or is there any way to do it using smart contract.
Thanks in advance.