2

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.

1
  • Please edit to be specific about what error(s) you're getting and include their stack traces etc. See also How to Ask Commented Aug 12 at 22:59

1 Answer 1

1

The address you are using is incorrect for Sepolia. Use the actual SwapRouter address for Sepolia: 0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E.

This should solve the main error that prevents MetaMask from opening.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.