Skip to main content
improved grammar
Source Link
President James K. Polk
  • 42.3k
  • 34
  • 113
  • 149

I am trying to swap 2two 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 is giving thegives an error. Everything else is working fine, just this line is givingcausing 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; } 

TriedI 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.

I am trying to swap 2 tokens A and B for which I have created the pool on Uniswap testnet Sepolia. But in Remix, when I try to execute the swap, it is giving the error. Everything else is working fine, just this line is giving 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; } 

Tried everything, but the swap call is giving error when I click on swap button. It doesn't even let MetaMask open, it gives the error before.

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.

fix code block formatting. fix various spelling and grammar issues. remove duplicate text
Source Link

I am trying to swap 2 tokens A,B and B for which I have created the pool on uniswapUniswap testnet sepolia butSepolia. But in remixwhenRemix, when I try to execute the swap, it is giving the error. Everything else is working fine, just this line is giving the issue

Let me know if the router address is incorrect for sepolia.

ISwapRouter public immutable uniswapRouter = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564); thisThis is the router address I have used for sepoliaSepolia, is it correct?

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");

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; } 

Tried everything, but the swap call is giving error when I click on swap button, it dont. It doesn't even let the metamaskMetaMask open, it gives the error before``before.

I am trying to swap 2 tokens A,B for which I have created the pool on uniswap testnet sepolia but in remixwhen I try to execute the swap it is giving the error. Everything else is working fine just this line is giving the issue

Let me know if the router address is incorrect for sepolia

ISwapRouter public immutable uniswapRouter = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564); this is the router address I have used for sepolia, is it correct

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; } 

Tried everything, but the swap call is giving error when I click on swap button, it dont even let the metamask open, gives the error before``

I am trying to swap 2 tokens A and B for which I have created the pool on Uniswap testnet Sepolia. But in Remix, when I try to execute the swap, it is giving the error. Everything else is working fine, just this line is giving 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; } 

Tried everything, but the swap call is giving error when I click on swap button. It doesn't even let MetaMask open, it gives the error before.

Source Link

Uniswap swapping tokens issue

I am trying to swap 2 tokens A,B for which I have created the pool on uniswap testnet sepolia but in remixwhen I try to execute the swap it is giving the error. Everything else is working fine just this line is giving the issue

Let me know if the router address is incorrect for sepolia

ISwapRouter public immutable uniswapRouter = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564); this is the router address I have used for sepolia, is it correct

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; } 

Tried everything, but the swap call is giving error when I click on swap button, it dont even let the metamask open, gives the error before``

created from staging ground