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