I have been running this small script to buy through the PCS router contract and as it works, the slippage is set to 0. I need to know how to find the value and what it expects so that i can set AmountOutMin as needed. It will work with 0 but only if trades are very slow.

const tx = await router.swapExactETHForTokens (
      0,                                  // AmountOutMin
      [addresses.WBNB, token],
      Math.floor(Date.now() / 1000) + 60 * 10,                     
          value: BNBAmount

I would like to know i obtain this value when Buying through PCS router. Nodejs, Ethersjs

New info :

So this is the minimum amount of tokens you are willing to accept then. So based on the percentage of slippage you want to use, and the amount of tokens that can be purchased for the amount you are spending, you calculate the least amount you are willing to accept and use this as AmountOutIn? Do you have to add the decimal? or can you just format it as BigNumber?


1 Answer 1


If I'm not wrong pancakeswap if uniswap v2 with a few changes, so you can use uniswap documentation:

In this particular case you have getAmountsOut than given the pair and the input amount it will return the expected output at the time of the call. You may need to adjust slippage.

  • Thank you for your time. I am using the PCS router contract. Im not sure if its the same value for Uniswap. Ive seen Hex values and BN values passed into this function. And it leaves some confusion as to which is the way. I have since figured out how to get the amont, yet It still fails at times. Using 0 should yield more consistent results. Must be a problem somewhere else in the code but it always uses the max gas even if its 25 gwei. And a txn on a very slow token should not take more than 5, 300000. Commented Aug 19, 2021 at 10:41
  • @gendisarray I can't comment on PCS, but the output amount depends on the liquidity available, if it changes in between it might fail. You can use a slippage percentage to take into considerations liquidity fluctuations fluctuations. Using 0 is equivalent to 100% slippage. There's no value that will work all the time it depends on the price fluctuations. I think uniswap uses 3%, but for tokens with higher fluctuations you'll have to use a higher value.
    – Ismael
    Commented Aug 19, 2021 at 16:22
  • Yes... As with Uniswap lib PCS also has one that figures AmountOutMin as well. Your input has been really helpful. I can do the calculations or i can use already exposed methods. The latter is the best way. Why do work thats already done? Thank you so much. Commented Aug 22, 2021 at 4:20

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.