0

I'm calling the swapExactTokensForETH in order to exchange some Eternal token for BNB. amountOutMin is set to 0 (I swap small amounts) and timestamp is set to uint256 max.

Here's an example of the transaction failing https://bscscan.com/tx/0x7be8f525ba3b075867c5d93ec094148e174a145e179ed46b478d4a5a235dac93

Trying again with the same parameters succeeds. https://bscscan.com/tx/0xca90130978fef9739edd31a87059a9a820c1a3a59be332c054d6397bdb8e09e6

What could be the cause for the first revert?

2
  • Looking at the call trace bscscan.com/… the first fails because of out of gas.
    – Ismael
    Oct 30, 2021 at 21:04
  • It looks like this is the right answer. Thank you. I would love to know why the gas estimation gets it wrong (I'm using ethers.js).
    – AdrienM
    Oct 31, 2021 at 0:02

1 Answer 1

0

You use 0 for second parameter it means you use 0 % slippage i suppose, so that means, when your transaction is included in a block and that block is mined, it will revert if you get less than number of tokens of first arg. you're supposed to use a slippage close to your price impact in the pool with a little extra margin in case the price go up before your transaction is accepted

3
  • The second parameter is "amountOutMin" docs.uniswap.org/protocol/V2/reference/smart-contracts/…. It's the minimum amount of token I'm willing to accept. Since it's zero, any amount will be accepted. Also, if the revert was due to this parameter, I think there should be a revert reason.
    – AdrienM
    Oct 30, 2021 at 8:30
  • right, i didn't checked the function code but assumed 0 was used as same input of first arg, but not. that's a bit crazy to not define a slippage though imho. "Gas Limit: 152,409 Gas Used by Transaction: 152,292 (99.92%) " you were just running out of gas maybe ? Oct 30, 2021 at 9:12
  • I don't define a slippage because my trades are small and always on the same LP that has enough liquidity. I don't think it runs out of gas because if the transaction had run out of gas it would be displayed by Bscscan. It would say something like "Out of gas". Moreover, the gas limit is calculated automatically and I don't have a reason to think it made a mistake.
    – AdrienM
    Oct 30, 2021 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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