General Questions about importing and inheriting

Hello,

I import ERC721Enumerable which in turn imports ERC721. Among other things, ERC721 imports Strings.

  1. In order to use the ERC721() in the constructor function i have to additionally import ERC721. Why? Example: constructor() ERC721("MyContract","ABC" ) Ownable(msg.sender) {}
  2. In order to use the .toString method, I also need to import Strings. Why?
  3. Currently I am inheriting my contract from "ERC721Enumerable" and "Ownable".
    When I try to additionally inherit from ERC721 and Strings, it won't compile.
    Example:
  • contract myContract is ERC721Enumerable, Ownable{} --> compiles
  • contract myContract is ERC721Enumerable,ERC721, Ownable, Strings{}--> compiles not

Obviously, I am missing something fundamental regarding imports. Could someone please explain this to me?

Many Thanks
J

hey @JP_1!

  1. You are only importing ERC721 once (via something like import {ERC721} from ..., and then marking the inheritance with something like myContract is ERC721 .... Because ERC721 has a constructor, you need to pass the constructor variables from myContract, which is the reason you need to do constructor() ERC721("MyContract","ABC" ) Ownable(msg.sender) {}
  2. Strings is not inherited by ERC721, so you need to import it separately. Once imported, you have to use it like Strings.toString
  3. Strings is a library, so it's cannot be inherited directly as abstract contracts (ERC721, etc.)

Check out this and this.

2 Likes

Thank you @cairoeth !
Ill dig into the links you provided.

Have a nice day!