0

I has set this amountOutMin parameter in my code, but the amount of token I received was still less than it. Why is it like this?

The transaction is https://bscscan.com/tx/0xc04715372ef2b25fe4cb8b2bf422721ef5b7266f804dc06ce8b84b4c5f056cd3. This is maded by using the code through Pancakeswap V2 router.

The amountOutMin in this case was 8443229148751464555872256, bought with 0.001BNB, but the token received was 7,675,662,862,501,330.751356287.

By contrast, I made another trascation by official Pancakeswap V2 website directly few minutes later. The transcation is https://bscscan.com/tx/0x352e89799b319a1dc4d22ed1367bb8b952223b85b28212a8f67d93ff075c6de9. In this case, the amountOutMin was 7603157464191205469747941, bought with 0.001BNB, and the token received was 7,663,982,723,904,740.113505927, which was fine.

Does some one know why it is like this?

And another concern I have is that if amountOutMin was useless, can I use this swapExactETHForTokens function to buy tokens at the moment of a project launch? Since I want to buy the tokens with the launch price. Is it dangerous? Because 1. I may buy the token at the peak 2. I heard there is a Man-in-the-middle attack, who buy the token at a lower price and then sell it to you with higher price, is it true?

0

If this token (ShibaZilla) charges fee on transfer, for example for sending tokens back to holders, or sending to liquidity pool or something like that, you shouldn't execute the swapExactETHForTokens function for it but the swapExactETHForTokensSupportingFeeOnTransferTokens function.

So amountOutMin is not useless.

Regarding man in the middle attack - it is called a sandwich. It's possible, and this is why you should set your amountOutMin to be as tight as you'd like. If you won't, then somebody might push up the price, make you get the minimal amountOutMin you supplied, and then he'll sell back his tokens for a small profit.

3
  • Why should I use the other function? Any differences? Do you mean the amountOutMin works when using swapExactETHForTokensSupportingFeeOnTransferTokens if buying the 'charging fee' tokens? And if I use the swapExactETHForTokens to buy 'charging fee' tokens, the amountOutMin is invalid, unless I buy a normal token?
    – ZhaiShang
    Nov 15 '21 at 18:17
  • The difference is that the SupportingFeeOnTransferTokens will calculate the correct amount for amountOutMin, taking into account the charging fee. "And if I use the swapExactETHForTokens to buy 'charging fee' tokens, the amountOutMin is invalid, unless I buy a normal token? " - yes. Nov 16 '21 at 3:58
  • So do you recommend to use swapExactETHForTokensSupportingFeeOnTransferTokens all the time? Because when it is a normal token, it works the same as swapExactETHForTokens, and if it is a 'charging fee' token, it takes the charging fees into account?
    – ZhaiShang
    Nov 16 '21 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.