1

I want to use the Uniswap router contract to buy a token. However, I got confused by the amountoutmin(unit256) in the swapExactETHForTokensSupportingFeeOnTransferTokens of uniswap. I read the unswap documentation and it says "The minimum amount of output tokens that must be received for the transaction not to revert." Please can someone suggest what I am expected to write there and what it means. Thank you.

enter image description here

1
  • So if it's a new token and it hasn't got any price yet, how do i calculate the slippage then, for instance a 5% slippage assuming it's an 18 decimal token Jun 3 '21 at 20:09
2

The Uniswap Router is a periphery contract which means that it's not strictly necessary. But still you should use it due to the fact that it protects you against various kinds of attacks on your trades.

One of the attack vectors is frontrunning your trades. That means you enter your trade, some bot notices it in the Ethereum mempool (before it's executed), creates their own trade which gets executed before your trade and their trade makes your trade less profitable for you.

To prevent this kinds of attacks the router provides various mechanisms; one of them is that amountoutmin. You could just send X amount of Eth to Uniswap and say "give me the maximum amount of tokens for this amount of Eth I give you" but that would be suspectible to frontrunning attacks. So you also need to specify how many tokens you want at minimum with amountoutmin. If the trading price has shifted too much between when you send the transaction and when it gets executed your trade gets reverted.

So you have to know in advance how many tokens you'd like to get, at minimum.

5
  • Thank you for this response. I understand this much better. I appreciate it. However, I have a question. If an interested token is 0.5 A = 1Eth, what is amounoutmin in unit256 if I don't want it after it pumps 2x should I insert. That should be 0.25 A, but in unit256, what would be the value?
    – Turpsy
    Nov 20 '20 at 14:19
  • You have to consider how many decimals the token has. If you'd get more, it's OK, but the safeguard is against the price dropping before your transaction completes Nov 20 '20 at 17:40
  • Ok, thanks. Assuming its an 18 decimal, what will be the equivalent of 0.25A in unit256? please.
    – Turpsy
    Nov 22 '20 at 0:35
  • 0.25 * (10 ^ 18) Nov 22 '20 at 6:47
  • Thank you . this solves my doubt.
    – Turpsy
    Nov 23 '20 at 1:39

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