2

I'm following this tutorial to understand Uniswap v3 better: https://docs.uniswap.org/protocol/guides/swaps/single-swaps

My contract:

pragma solidity ^0.7.6;
pragma abicoder v2;

import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";

contract SwapExamples {
    ISwapRouter public immutable swapRouter;

    address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
    address public constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;

    uint24 public constant POOL_FEE = 3000;

    constructor(ISwapRouter _swapRouter) {
        swapRouter = _swapRouter;
    }

    function swapExactInputSingle(uint256 amountIn) external returns (uint256 amountOut) {
        TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountIn);

        TransferHelper.safeApprove(DAI, address(swapRouter), amountIn);

        ISwapRouter.ExactInputSingleParams memory params = 
            ISwapRouter.ExactInputSingleParams({
                tokenIn: DAI,
                tokenOut: WETH9,
                fee: POOL_FEE,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountIn: amountIn,
                amountOutMinimum: 0,
                sqrtPriceLimitX96: 0
            });

        amountOut = swapRouter.exactInputSingle(params);
    }

    /// @notice swapExactOutputSingle swaps a minimum possible amount of DAI for a fixed amount of WETH.
    /// @dev The calling address must approve this contract to spend its DAI for this function to succeed. As the amount of input DAI is variable,
    /// the calling address will need to approve for a slightly higher amount, anticipating some variance.
    /// @param amountOut The exact amount of WETH9 to receive from the swap.
    /// @param amountInMaximum The amount of DAI we are willing to spend to receive the specified amount of WETH9.
    /// @return amountIn The amount of DAI actually spent in the swap.
    function swapExactOutputSingle(uint256 amountOut, uint256 amountInMaximum) external returns (uint256 amountIn) {
        // Transfer the specified amount of DAI to this contract.
        TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountInMaximum);

        // Approve the router to spend the specified `amountInMaximum` of DAI.
        // In production, you should choose the maximum amount to spend based on oracles or other data sources to achieve a better swap.
        TransferHelper.safeApprove(DAI, address(swapRouter), amountInMaximum);

        ISwapRouter.ExactOutputSingleParams memory params =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: DAI,
                tokenOut: WETH9,
                fee: POOL_FEE,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountOut: amountOut,
                amountInMaximum: amountInMaximum,
                sqrtPriceLimitX96: 0
            });

        // Executes the swap returning the amountIn needed to spend to receive the desired amountOut.
        amountIn = swapRouter.exactOutputSingle(params);

        // For exact output swaps, the amountInMaximum may not have all been spent.
        // If the actual amount spent (amountIn) is less than the specified maximum amount, we must refund the msg.sender and approve the swapRouter to spend 0.
        if (amountIn < amountInMaximum) {
            TransferHelper.safeApprove(DAI, address(swapRouter), 0);
            TransferHelper.safeTransfer(DAI, msg.sender, amountInMaximum - amountIn);
        }
    }
}

It compiles well: enter image description here

I did use Alchemy.io to fork the mainnet: enter image description here

I took the latest block number from https://etherscan.io/blocks

And ran it as follows: yarn hardhat node assuming my default one will be forking mainnet, and it seems so it did.

This tutorial proposes this constructor:

enter image description here

I found the SwapRouter here: https://etherscan.io/address/0xe592427a0aece92de3edee1f18e0157c05861564

So what I tried to do in my Hardhat deployment script is the following: enter image description here

And got this: enter image description here

Tried changing as image suggested above to:

const { ethers } = require("hardhat");

async function main() {
    console.log("Getting contract");
    //const SwapRouter = await ethers.getContractFactory("SwapRouter");
    const SwapRouter = await ethers.getContractAt("ISwapRouter", "0xE592427A0AEce92De3Edee1F18E0157C05861564");
    const Contract = await ethers.getContractFactory('SwapExamples');
    await Contract.deploy(SwapRouter);
}

main()
.then(() => process.exit(0))
.catch(error => {
    console.error(error);
    process.exit(1);
})

I've got this log error:

$ /home/deb0rian/Projects/swap-example/node_modules/.bin/hardhat run scripts/deploy-swap.js
Getting contract
Error: invalid address or ENS name (argument="name", value={"interface":{"fragments":[{"type":"function","name":"exactInput","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"path","type":"bytes","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"bytes","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOutMinimum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},{"type":"function","name":"exactInputSingle","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"tokenIn","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"tokenOut","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"fee","type":"uint24","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint24","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOutMinimum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"sqrtPriceLimitX96","type":"uint160","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint160","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},{"type":"function","name":"exactOutput","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"path","type":"bytes","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"bytes","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountInMaximum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},{"type":"function","name":"exactOutputSingle","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"tokenIn","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"tokenOut","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"fee","type":"uint24","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint24","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountInMaximum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"sqrtPriceLimitX96","type":"uint160","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint160","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},{"type":"function","name":"uniswapV3SwapCallback","constant":false,"inputs":[{"name":"amount0Delta","type":"int256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"int256","_isParamType":true},{"name":"amount1Delta","type":"int256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"int256","_isParamType":true},{"name":"data","type":"bytes","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"bytes","_isParamType":true}],"outputs":[],"payable":false,"stateMutability":"nonpayable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true}],"_abiCoder":{"coerceFunc":null},"functions":{"exactInput((bytes,address,uint256,uint256,uint256))":{"type":"function","name":"exactInput","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"path","type":"bytes","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"bytes","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOutMinimum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},"exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))":{"type":"function","name":"exactInputSingle","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"tokenIn","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"tokenOut","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"fee","type":"uint24","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint24","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOutMinimum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"sqrtPriceLimitX96","type":"uint160","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint160","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},"exactOutput((bytes,address,uint256,uint256,uint256))":{"type":"function","name":"exactOutput","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"path","type":"bytes","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"bytes","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountInMaximum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},"exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))":{"type":"function","name":"exactOutputSingle","constant":false,"inputs":[{"name":"params","type":"tuple","indexed":null,"components":[{"name":"tokenIn","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"tokenOut","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"fee","type":"uint24","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint24","_isParamType":true},{"name":"recipient","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true},{"name":"deadline","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountOut","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"amountInMaximum","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true},{"name":"sqrtPriceLimitX96","type":"uint160","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint160","_isParamType":true}],"arrayLength":null,"arrayChildren":null,"baseType":"tuple","_isParamType":true}],"outputs":[{"name":"amountIn","type":"uint256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"uint256","_isParamType":true}],"payable":true,"stateMutability":"payable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true},"uniswapV3SwapCallback(int256,int256,bytes)":{"type":"function","name":"uniswapV3SwapCallback","constant":false,"inputs":[{"name":"amount0Delta","type":"int256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"int256","_isParamType":true},{"name":"amount1Delta","type":"int256","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"int256","_isParamType":true},{"name":"data","type":"bytes","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"bytes","_isParamType":true}],"outputs":[],"payable":false,"stateMutability":"nonpayable","gas":{"type":"BigNumber","hex":"0x01ba8140"},"_isFragment":true}},"errors":{},"events":{},"structs":{},"deploy":{"name":null,"type":"constructor","inputs":[],"payable":false,"stateMutability":"nonpayable","gas":null,"_isFragment":true},"_isInterface":true},"provider":"<WrappedHardhatProvider>","signer":"<SignerWithAddress 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266>","callStatic":{},"estimateGas":{},"functions":{},"populateTransaction":{},"filters":{},"_runningEvents":{},"_wrappedEmits":{},"address":"0xE592427A0AEce92De3Edee1F18E0157C05861564","resolvedAddress":{}}, code=INVALID_ARGUMENT, version=contracts/5.6.2)
    at Logger.makeError (/home/deb0rian/Projects/swap-example/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/home/deb0rian/Projects/swap-example/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at Logger.throwArgumentError (/home/deb0rian/Projects/swap-example/node_modules/@ethersproject/logger/src.ts/index.ts:277:21)
    at /home/deb0rian/Projects/swap-example/node_modules/@ethersproject/contracts/src.ts/index.ts:123:16
    at step (/home/deb0rian/Projects/swap-example/node_modules/@ethersproject/contracts/lib/index.js:48:23)
    at Object.next (/home/deb0rian/Projects/swap-example/node_modules/@ethersproject/contracts/lib/index.js:29:53)
    at fulfilled (/home/deb0rian/Projects/swap-example/node_modules/@ethersproject/contracts/lib/index.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  reason: 'invalid address or ENS name',
  code: 'INVALID_ARGUMENT',
  argument: 'name',
  value: Contract {
    interface: Interface {
      fragments: [Array],
      _abiCoder: [AbiCoder],
      functions: [Object],
      errors: {},
      events: {},
      structs: {},
      deploy: [ConstructorFragment],
      _isInterface: true
    },
    provider: EthersProviderWrapper {
      _isProvider: true,
      _events: [],
      _emitted: [Object],
      disableCcipRead: false,
      formatter: [Formatter],
      anyNetwork: false,
      _networkPromise: [Promise],
      _maxInternalBlockNumber: -1024,
      _lastBlockNumber: -2,
      _maxFilterBlockRange: 10,
      _pollingInterval: 4000,
      _fastQueryDate: 0,
      connection: [Object],
      _nextId: 42,
      _hardhatProvider: [BackwardsCompatibilityProviderAdapter],
      _eventLoopCache: [Object],
      _network: [Object]
    },
    signer: SignerWithAddress {
      _isSigner: true,
      address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
      _signer: [JsonRpcSigner],
      provider: [EthersProviderWrapper]
    },
    callStatic: {
      'exactInput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                         
      'exactOutput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                        
      'uniswapV3SwapCallback(int256,int256,bytes)': [Function (anonymous)],
      exactInput: [Function (anonymous)],
      exactInputSingle: [Function (anonymous)],
      exactOutput: [Function (anonymous)],
      exactOutputSingle: [Function (anonymous)],
      uniswapV3SwapCallback: [Function (anonymous)]
    },
    estimateGas: {
      'exactInput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                         
      'exactOutput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                        
      'uniswapV3SwapCallback(int256,int256,bytes)': [Function (anonymous)],
      exactInput: [Function (anonymous)],
      exactInputSingle: [Function (anonymous)],
      exactOutput: [Function (anonymous)],
      exactOutputSingle: [Function (anonymous)],
      uniswapV3SwapCallback: [Function (anonymous)]
    },
    functions: {
      'exactInput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                         
      'exactOutput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                        
      'uniswapV3SwapCallback(int256,int256,bytes)': [Function (anonymous)],
      exactInput: [Function (anonymous)],
      exactInputSingle: [Function (anonymous)],
      exactOutput: [Function (anonymous)],
      exactOutputSingle: [Function (anonymous)],
      uniswapV3SwapCallback: [Function (anonymous)]
    },
    populateTransaction: {
      'exactInput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                         
      'exactOutput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
      'exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                        
      'uniswapV3SwapCallback(int256,int256,bytes)': [Function (anonymous)],
      exactInput: [Function (anonymous)],
      exactInputSingle: [Function (anonymous)],
      exactOutput: [Function (anonymous)],
      exactOutputSingle: [Function (anonymous)],
      uniswapV3SwapCallback: [Function (anonymous)]
    },
    filters: {},
    _runningEvents: {},
    _wrappedEmits: {},
    address: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
    resolvedAddress: Promise { '0xE592427A0AEce92De3Edee1F18E0157C05861564' },
    'exactInput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
    'exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                           
    'exactOutput((bytes,address,uint256,uint256,uint256))': [Function (anonymous)],
    'exactOutputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))': [Function (anonymous)],                                                                                                          
    'uniswapV3SwapCallback(int256,int256,bytes)': [Function (anonymous)],
    exactInput: [Function (anonymous)],
    exactInputSingle: [Function (anonymous)],
    exactOutput: [Function (anonymous)],
    exactOutputSingle: [Function (anonymous)],
    uniswapV3SwapCallback: [Function (anonymous)]
  }
}
error Command failed with exit code 1.

Can anyone point me to a mistake?

Thanks a lot

2 Answers 2

0

You didn't share your contract code, but the code in the tutorial you've linked to uses contract name SwapExamples, and in your Hardhat script you're trying to get swapExample.

1
  • Yeah, sorry for that, my contract is equal to the one in the tutorial, apart from the name not being plural, so that's fine. But my deployment doesn't even get to that part. It's stuck on getting the SwapRouter from the testnet.
    – deb0rian
    Jul 3, 2022 at 8:57
0

Found an answer here: https://github.com/ethers-io/ethers.js/issues/1051

Apparently, you cannot pass as an argument to the constructor as the Contract object itself, rather you have to pass its address, pay attention to this:

const SwapRouter = await ethers.getContractAt("ISwapRouter", "0xE592427A0AEce92De3Edee1F18E0157C05861564");
await Contract.deploy(SwapRouter);

Should become this:

const SwapRouter = await ethers.getContractAt("ISwapRouter", "0xE592427A0AEce92De3Edee1F18E0157C05861564");
await Contract.deploy(SwapRouter.address); // FIX HERE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.