Hi all, I am trying to do a swapping functionality in Georli Base Network using the uniswapV3 interface, I got the gas Estimation Error. Below is My code,
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.6;
pragma abicoder v2;
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import "@uniswap/swap-router-contracts/contracts/interfaces/IV3SwapRouter.sol";
contract SwapExamples {
// For the scope of these swap examples,
// we will detail the design considerations when using
// `exactInput`, `exactInputSingle`, `exactOutput`, and `exactOutputSingle`.
// It should be noted that for the sake of these examples, we purposefully pass in the swap router instead of inherit the swap router for simplicity.
// More advanced example contracts will detail how to inherit the swap router safely.
ISwapRouter public immutable swapRouter;
// This example swaps DAI/WETH9 for single path swaps and DAI/USDC/WETH9 for multi path swaps.
address public constant DAI = 0x2e0235D18A5B57c6406fe6bb7B921409Be4ADC3c;
address public constant WETH9 = 0x4200000000000000000000000000000000000006;
address public constant USDC = 0xb5e6184d517cb963f26cE6ebe2Fd0C0c3758a0e8;
// For this example, we will set the pool fee to 0.3%.
uint24 public constant poolFee = 3000;
address private constant SWAP_ROUTER_02 = 0x8357227D4eDc78991Db6FDB9bD6ADE250536dE1d;
IV3SwapRouter public immutable swapRouter02 = IV3SwapRouter(SWAP_ROUTER_02);
function swapExactOutputSingle(uint256 amountIn ) external returns (uint256 amountOut) {
// Transfer the specified amount of DAI to this contract.
TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountIn);
// Approve the router to spend DAI.
TransferHelper.safeApprove(DAI, address(swapRouter02), amountIn);
IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter
.ExactInputSingleParams({
tokenIn: DAI,
tokenOut: WETH9,
fee: 3000,
recipient: address(this),
amountIn: amountIn,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
amountOut = swapRouter02.exactInputSingle(params);
}
function swapExactOutputSingle1(uint256 amountIn ) external returns (uint256 amountOut) {
IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter
.ExactInputSingleParams({
tokenIn: DAI,
tokenOut: USDC,
fee: 3000,
recipient: address(this),
amountIn: amountIn,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
amountOut = swapRouter02.exactInputSingle(params);
}
}
This is the code ,which I used,i am trying to call the swapExactOutputSingle
,But i got gas estimation problem,
below are the Contract details:
1)Contract address:0x8a483Bf7946f7AA6557a8C06BBFA369994D301e6
2)Wallet address:0xd72558AB56489747360657ab4802176Ce18B49E5
3)Dai address:0x2e0235D18A5B57c6406fe6bb7B921409Be4ADC3c
4)Transaction hash:https://goerli.basescan.org/tx/0x115bd3525ae04453de83fe6a6063ff6ca708cc73110c86935fe3281d69b06e7f