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?