0

I'm getting an error on the addLiquidity() method of Uniswap's Router (UniswapV2Router02.sol) using my own deployed version of the contract on a testnet. I'm using Remix, and am receiving the message: "Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }"

For testing purposes, I've created two ERC20 tokens, let's call them TOK1, TOK2.

I minted myself 100 of TOK1 and 100 of TOK2

I called the approve function on both TOK1 and TOK2 contract with my wallet address

I compiled + deployed the Uniswap Factory (UniswapV2Factory) as well as the UniswapV2Router02

I set up the Router (init() method) by providing the Factory address that I deployed (above), and the address of TOK1 (also above).

I then try to call the addLiquidity(..) method with the following parameters:

tokenA = TOK1 address
tokenB = TOK2 address
amountADesired = 1 (in wei => 1000000000000000000)
amountBDesired = 1 (in wei => 1000000000000000000)
amountAMin = 0.1 (in wei => 100000000000000000)
amountBMin = 0.1 (in wei => 100000000000000000)
to: my wallet address
deadline: unix timestamp + 20 minutes

This results in the above gas estimation error message from Remix. I've tried changing the Gas limits as well as the Value field in the Deploy & Run Transactions window of Remix. Neither seems to have any effect.

Is there something that needs to be done first?

3
  • Check if the init code hash in the UniswapV2Library is correct: ethereum.stackexchange.com/questions/88075/… May 25 at 21:15
  • You saved me! I've been messing around with this for about 6 hours today and the answer was that init code hash piece. If you want to provide an answer with this as the solution, I'll select it.
    – meoww-
    May 25 at 21:47
  • I suffered for the same reason for days too...just rewrote the comment as answer however. May 25 at 21:51
1

It is likely that the init code hash in the UniswapV2Library is incorrect: Uniswap addLiquidity function transaction revert

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.