0

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!

1 Answer 1

1

You need to approve, yes. In solidity, just is this:

IERC20(address(token)).approve(address(router), amountToApprove);

So, you just need to convert it to the language you are using, if you are not using solidity.

In ether.js, what I suppose you are using, check this:

Execute transaction Approve directly against contract address (without ABI)

0

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.