// 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';

contract SwapExamples {

    ISwapRouter public immutable swapRouter;

    constructor(ISwapRouter _swapRouter) {
        swapRouter = _swapRouter;

What does the constructor expect during contract creation? Is it asking for an address and is implicitly type casting that into the interface type? Or is there something like passing an interface type during contract creation?

1 Answer 1


Interface and contract types in solidity are just compile time wrappers around an address. If you look at the generated abi filed for your code you will see that the parameter type expected is an address. And actually the generated bytecode will not perform any type checks on this address. If you want to check if a specific address implements an interface I would recommend you to look into EIP-165.

  • So is the interface we import/include in our contract code just syntactic sugar for compiler to not yell "function not defined" errors?
    – Pranay
    Jan 7, 2022 at 10:32
  • Also, solidity says we can't instantiate an interface (similar to abstract contracts). Then how does this work here?
    – Pranay
    Jan 7, 2022 at 10:37
  • Yes it is more "syntactic sugar" to perform compile time checks. To instantiate a contract you would require the source code to create the deployment/runtime code for it. But in your example you only want to interact with a contract of the specified type and therefore only the ABI definition is required.
    – Richard
    Jan 7, 2022 at 12:42
  • At low level, does calling a contract like contractFromAddress.foo(params) simply translate to a call? That'll be the last of questions, Thanks!
    – Pranay
    Jan 7, 2022 at 14:48
  • Yes, and it will also check if the response is in a format that fits the expected type
    – Richard
    Jan 7, 2022 at 16:38

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.