My code is pretty simple

function swapForEth(address tokenAddress, 
    uint amountIn, 
    uint amountOutMin, 
    address to, 
    uint deadline) external onlyOwner payable {

    require(IERC20(tokenAddress).approve(UNISWAP_ROUTER_ADDRESS, uint256(-1)));

    address[] memory path = new address[](2);
    path[0] = tokenAddress;
    path[1] = uniswap.WETH();

    uniswap.swapExactTokensForETH(amountIn, amountOutMin, path, to, deadline);

As you can see. I am approving the token with uint256(-1) so not sure the error i am getting in my transaction is TRANSFER_FROM_FAILED

Please see transaction here https://kovan.etherscan.io/tx/0x86d4667699a86bc0bd49d7ae54bfb51b406c25f08b499b0a607e2d974bb68c68

I'd verify the contract bytecode but unfortunately I've changed my contract a bit since then so having some trouble doing so lol... if needed can post a larger portion of the contract

  • Hi there. The error will be coming from the .swapExactTokensForETH() call, so you'll need to check the sanity of all the arguments you're passing in. – Richard Horrocks May 15 at 7:51
  • Thanks Richard! It definitely is coming from that call, but I think the error implies that my contract is not approved to transfer the tokens - but my require statement does that? Very confused. – k9b May 15 at 7:56
  • Can you check the allowance for tokenAddress/UNISWAP_ROUTER_ADDRESS by calling allowance() on the ERC20 contract manually? If that checks out, then it's not the approval that's the issue. – Richard Horrocks May 15 at 7:58
  • Hmm it seems the allowance is still 0... gyazo.com/363306b760c5c47d164641d07b603150 My contract does not appear to have approved the UniswapV2 contract – k9b May 15 at 8:31
  • And also no emitted events here. ethtx.info/kovan/… – k9b May 15 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.