Why INSUFFICIENT_OUTPUT_AMOUNT?

  • enter image description here

    I sent this transaction with 74 GWEI and 185421 gas limit. So far my calculations: 74 * 185421 -> about 6.6 USD, at the time of writing.

    The screenshot above shows 1.04 USD. Below it says gas used ~15%.

    What's going on? Why does the transaction stop at 15% of the limit (if I understand this correctly)?

  • The error-message INSUFFICIENT_OUTPUT_AMOUNT is thrown from the contract function, not from the transaction.

    It therefore has nothing to do with your gas-limit and gas-price configuration, and it most certainly has nothing to do with ETH/USD price.

    This error-message tells you that the output amount is smaller than the minimum that you've requested for (in the amountOutMin input parameter which you have passed to this function).

    You can observe all of this in the contract source code on GitHub.

    Ah okay, lol, I was very mistaken. So I've to increase the slippage.

    My problem was actually that I wasn't using `JSBI.toNumber` on the amount returned by uniswap to convert it to an actual number, so it was sending a ridiculously high amount. It makes sense to switch to Typescript. JS is too dangerous for this.

    @Ixx: Never use `toNumber` on anything returned from a web3 call without asserting first that it is not larger than `Number.MAX_SAFE_INTEGER`.

    For example, `if (retVal.lte(new BN(Number.MAX_SAFE_INTEGER))) ...`.

    More generally, I would recommend to avoid even that suggestion, and use only `BN` objects throughout your code. That is, unless it is designated for display purpose, in which case, you can and should use `toString()`.

    BN is what's returned from the Uniswap SDK? If it is, this is what I was using first (calling raw on it), but I can't pass that to the web3 transaction, because it expects a plain number. Probably missing something, not at the computer right now.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM