We are trying to "swapExactTokensforTokens" for swapping any token, and it runs well, but we get this error at the blockchain:
TRANSFER_FROM_FAILED
https://polygonscan.com/tx/0xf584e421990628131b92b22b2aad270e91752287817eeb518a4d9bdb4b37d086
When we use "swapETHForExactTokens" it makes the trade, but can only use MATIC/ETH/BNB as token1. Do you know how to solve this?
CODE (we are not approving contracts before, we don't know how to do it).
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
data.recipient,
Date.now() + 1000 * 60 * 5, //5 minutes
{
'gasLimit': data.gasLimit,
'gasPrice': data.gasPrice
});
Thanks!