Import vs Import and inherit

It occurred ot me today that there is something about imports I don’t quite get.

What is the practical difference between:

  1. simply importing a contract in the head of your sol file, versus

  2. importing that contract AND ALSO using the ‘is’ keyword referring to that contract in your contract declaration

And follow up questions 3 and 4 would be the same as above, but if it was an interface instead of a contract you were importing.

1 Like

Hi @CryptoEatsTheWorld,

Importing imports all the global symbols from the file being imported into the current global scope.

See the Solidity documentation for details on imports:

An example of importing where you are not inheriting is using utilities such as SafeMath or Counters:

is means that your contract inherits from another contract.
contract MyToken is ERC20 means that your token inherits from the OpenZeppelin Contracts ERC20 implementation.

See the Solidity documentation for details on inheritance:

Also see the OpenZeppelin Contracts documentation on extending:

An example of importing where you are inheriting is extending from ERC20Burnable and ERC20Pausable:

  1. simply importing an interface in the head of your sol file, versus

Importing an interface would allow you to declare variables of an interface type to interact with contracts using the interface.

See the Solidity documentation for details on interfaces:

An example of importing an interface where you are not inheriting is using IERC20 to interact with an ERC20 contract:

  1. importing that interface AND ALSO using the ‘is’ keyword referring to that interface in your contract declaration

Importing and inheriting from an interface is just like inheriting from any other contract. Just like an abstract contract you would need to implement the functions defined in the interface.

An example of importing and inheriting from an interface is inheriting from IERC20:

1 Like

Hi @CryptoEatsTheWorld,

Did you need any more information?

No, thanks for the info.

1 Like