0

enter image description here

I used transferFrom and approve, but still got this error:

execution reverted: UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT.

I read the source code of Uniswap, in_ may be 0 ?

This problem has been solved, and now there are new error, execution reverted,There should be an error during the swap

This is my complete code

  function swap3(uint256 amountIn,uint256 amountOutMin,IRouter _router, IERC20[] calldata path, uint256 deadline
    ) external payable returns (bool b)  {
            require(address(path[0]) != address(0) , "path[0] error________");
            require(address(path[1]) != address(0),"path[1] error________");
            require(address(_router) != address(0) ,"_router error________");
            require(amountIn > 0 ,"amountIn must be > 0");
            IERC20 er = IERC20(path[0]);
            address[] memory n_path = new address[](2);
            n_path[0] = address(path[0]);
            n_path[1] = address(path[1]);
            require(er.transferFrom(msg.sender, address(this), amountIn),"transferFrom failed______");
            require(er.approve(address(_irouter), amountIn),"approve failed_______");
            require(er.balanceOf(address(this)) > 0 ," contract no money_______");
            IRouter(_router).swapExactTokensForTokens(amountIn,amountOutMin,n_path,msg.sender,deadline);
            return true;
    }

I don't know how to solve it now

1 Answer 1

0

The error (link to code) happens when the starting amount (in_) or an intermediate amount is 0.

So you need to use in_ > 0 and make sure that n_path has enough liquidity to output amounts > 0.

2
  • bruh,Thank you very much for your help,This problem has been solved, and now there are new error, [execution reverted],There should be an error during the swap
    – zhongyi du
    Sep 29, 2022 at 2:25
  • You're approving _irouter but then calling _router. Is it a typo?
    – 0xSanson
    Sep 29, 2022 at 11:13

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.