1

I am using the method: swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline).
How to determine the path router of a swap in address[] calldata path
Someone's path is 3 addresses, another is 2 addresses

1 Answer 1

2

if i got your question correctly, you would like to determine when have 2 address or 3 address in your path.

There are instances where you would like to trade your tokenA and tokenB through WETH. That is from tokenA to WETH then from WETH to tokenB. The reason being, some times it results in a better price. In such cases your path will have 3 Addresses [tokenA, WETH, tokenB].

If you want a direct swap or one of your token pools has WETH already then you can have two addresses. Find below snippet on how you can check and choose between 3 addresses and 2 address.

    address[] memory path;
    if (tokenA == WETH || tokenB == WETH) {
      path = new address[](2);
      path[0] = tokenA;
      path[1] = tokenB;
    } else {
      path = new address[](3);
      path[0] = tokenA;
      path[1] = WETH;
      path[2] = tokenB;
    }
1
  • Thank for you answer. I take the example of FLURRY. It has 3 pairs of liquidity FLURRY/WBNB FLURRY/BUSD FLURRY/USDT. I use swap coin98 link here. Case 1: Swap BUSD => FLURRY, its path is BUSD > USDC > FLURRY. Case 2: Swap USDT => FLURRY, its path USDT > UST > USDC > FLURRY. Both Case1 and Case2 confuse me
    – BaoNX
    Commented Dec 13, 2021 at 3:55

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.