when calling the following code from a js script a get "Error: cannot estimate gas; transaction may fail or may require manual gas limit " , how to fix this error ? :

function getAmountOutMin(address router, address _tokenIn, address _tokenOut, uint256 _amount) public view returns (uint256) {
    address[] memory path;
    path = new address[](2);
    path[0] = _tokenIn;
    path[1] = _tokenOut;
    uint256[] memory amountOutMins = IUniswapV2Router(router).getAmountsOut(_amount, path);
    return amountOutMins[path.length -1];

1 Answer 1


This error pops when something is wrong while calling the contract functions. Few things you should check.

You should be passing the arguments correctly, as I see there are so many parameters in the function. Make sure your function is correct, i.e. there is no internal error within the function when you are calling the uniswap function

Your Answer

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

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