1

I have assigned 'uint amountOutMin' as 1. But when I swap 0.1BNB to btc, amoutOutMin will be less than 1. Will this transaction revert (since amountOutMin is <1). I belive we cannot set it to a value like 0.0001

function swapExactTokensForTokens(
  uint amountIn,
  uint amountOutMin,
  address[] calldata path,
  address to,
  uint deadline
) external returns (uint[] memory amounts);

I am curious because I am getting the error message,

Error: cannot estimate gas; transaction may fail or may require manual gas limit
reason="execution reverted: TransferHelper: TRANSFER_FROM_FAILED"

I have approved the amounts for the router before hand, and the first transaction always goes through, and the subsequent transactions fails with the error message. The function is as follows

function swap (address _router, address _tokenIn, address _tokenOut, uint _amount) private onlyOwner {
    IERC20(_tokenIn).approve(_router,_amount);  // Approve router to spend.
    address[] memory path;  
    path = new address[](2);
    path[0] = _tokenIn;
    path[1] = _tokenOut;
    uint deadline = block.timestamp+300;
    IUniswapV2Router02(_router).swapExactTokensForTokens(_amount,1,path, address(this), deadline);
}

I am trying to debug the error, and want to eleminate this as a potential culprit.

DeFi
  • 77
  • 1
  • 8

0 Answers0