I am trying to swap two tokens A and B for which I have created the pool on the Uniswap testnet Sepolia. But in Remix, when I try to execute the swap, it gives an error. Everything else is working fine, just this line is causing the issue.
This is the router address I have used for Sepolia, is it correct?
ISwapRouter public immutable uniswapRouter = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564); function swapTokens(address _from, address _to, uint256 _amount) public{ require(_from!=_to,"Both the address can't be same"); require(userHolding[msg.sender][_from]>=_amount,"Sorry, you do not have the required amount of funds, please check the balance first"); // TransferHelper.safeApprove(_from, address(uniswapRouter), 0); TransferHelper.safeApprove(_from, address(uniswapRouter), 0); TransferHelper.safeApprove(_from, address(uniswapRouter), _amount); ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({ tokenIn: _from, tokenOut: _to, fee: poolFee, recipient: address(this), deadline: block.timestamp + 900, amountIn: _amount, amountOutMinimum: 0, sqrtPriceLimitX96: 0 }); // The call to `exactInputSingle` executes the swap. uint256 amountOut = uniswapRouter.exactInputSingle(params); // userHolding[msg.sender][_from]-=_amount; // userHolding[msg.sender][_to]+=amountOut; } I tried everything, but the swap call is giving an error when I click on the swap button. It doesn't even let MetaMask open, it gives the error before.