Circular imports?

jgostylojgostylo Posts: 5
I am trying to figure out what I am supposed to do in this instance.

I have a hub/spoke relationship set up with a couple of contracts. The hub contract creates the spoke contract and the spoke has calls back to the hub.

When I don't have an import in each then I get an "Identifier not found" error but when I do a circular include I get "Identifier already declared".

This works when the entire thing is one file but then I don't know how to output the ABI for the non-hub contract since that is what is getting deployed.

I am doing this as a means of security and identity management as I want the the hub to only trust calls it gets from its spokes for some functionality.

I am using truffle as my development environment.

Comments

  • mpolcimpolci Posts: 2
    I have the same problem.
  • jgostylojgostylo Posts: 5
    mpolci. I have spoken with other ethereum developers and the answer is "use abstract contracts". There are plenty of good reasons to use abstract contracts and for me this is on the top of the list. So import the abstract contract and use it whenever you need to use a contract that has already been created ie. AbstractWhatever(address). The only time you use contract Whatever is when you are creating a new contract.
  • rguikersrguikers Posts: 1
    jgostylo, can you please elaborate on that?. When using abstract contracts the import problem still exists. So only usable within one file. I also wonder how this abstract contract is used. Do both (hub and spoke) implement the same abstract contract in your case?
    Thanks for more information on this.
Sign In or Register to comment.