UniswapV3Router

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

Please share the relevant details, for example:

  • Which contract function you are trying to execute
  • What input values you are passing to that function
  • What input values you are using in the transaction itself (ETH value, etc)
  • The transaction hash or a link to it

When i am trying to call the swapExactInputSingle ,in remix i got gas estimation error

Prior to executing the contract function which executes the line above, have you executed DAI.approve(yourContractAddress, amountIn)?

Yes I executed this line ,by approving from my wallet manually

Please prove this claim, by sharing:

  • Your contract address
  • Your wallet address
  • DAI token address
  • Transaction hash

1)contract address:0xDFb10066A49acacE5910c11e8B6c1d9Fe4CdDC15
2)wallet address:0xd72558AB56489747360657ab4802176Ce18B49E5
3)DAI token address:0x2e0235D18A5B57c6406fe6bb7B921409Be4ADC3c

I have found this transaction (on Base blockchain / Goerli network), indicating that you have indeed approved your contract to transfer 74999989 DAI tokens from your wallet.

But I have not found any failed transaction indicating that you have indeed tried to execute a function on the same contract, using the same wallet.

Can you please share a link to that failed transaction (similar to the links above)?

Also, can you please verify your contract source code on goerli.basescan.org?

Before i am doing transaction it throws error,

This:

And this:

Don't match!

1)Contract address:0x8a483Bf7946f7AA6557a8C06BBFA369994D301e6
2)Wallet address:0xd72558AB56489747360657ab4802176Ce18B49E5
3)Dai address:0x2e0235D18A5B57c6406fe6bb7B921409Be4ADC3c
4)Transaction hash:https://goerli.basescan.org/tx/0x115bd3525ae04453de83fe6a6063ff6ca708cc73110c86935fe3281d69b06e7f

This the latest one mate,i am trying to execute swapExactOutputSingle this function

Listen mate - please sort out your stuff, then post exact details:

  • Exact description (for example, specify "goerli", and not just "testnet")
  • Exact addresses, including a proper link to each address on goerli basescan
  • Exact configuration details (for example, what do you initialize swapRouter to?)
  • Exact transaction details (which contract function you're calling and what input you're passing to it)
  • Any additional information which might be relevant for the investigation (transaction hashes, etc)

Don't make your readers work hard trying to figure out your problem!

Sorry mate,I am wrongly posted the old Contract mate,Now i updated that mate

This is my updated one mate,i am using swap router as

0x8357227D4eDc78991Db6FDB9bD6ADE250536dE1d this address

Dude - ALL the relevant details, in a SINGLE post.

Go over this entire thread if necessary, and gather them up.

Once you're done, you can just rewrite the original question.

Yes mate,Now i rewrite the question clearly,can you check once again mate

Mate can you please help me.

You're cheating the compiler to assume that a V2 contract implements the V3 interface (by casting the address of a V2 contract to a V3 interface).

That V2 contract doesn't implement function exactInputSingle, hence your transaction reverts at:

amountOut = swapRouter02.exactInputSingle(params);

In Base documentation they give this address only for V3 interface ,