0

I am trying to swap using WETH from my contract to DAI using swapExactTokensForTokens(amountIn, amountOutMin, getPathForETHtoToken(tokenAddress), address(this), deadline) with uniswap. First I approved large amount on both DAI and WETH address then I deposited 0.01 worth of WETH using:

function wrap() public payable restricted {
    if (msg.value != 0) {
      WETH.deposit{value : msg.value}();
      WETH.transfer(address(this), msg.value);
    }
  }

on my contract and now able to see the balance in WETH Next on remix I filled out the parameters for my swap function

function Buy(uint amountIn, uint amountOutMin, uint deadline, address tokenAddress) external payable restricted {
    uniswapRouter.swapExactTokensForTokens(amountIn, amountOutMin, getPathForETHtoToken(tokenAddress), address(this), deadline);
}

// amountIn = 10000000000000000, amountOutMin = 4029840000000000000, etc

And when I execute I get this error

Fail with error 'TransferHelper: TRANSFER_FROM_FAILED'

How do I resolve this issue?

1 Answer 1

0

In my case I had to call approve on the from token again, just before calling swap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.