1

I am working on a Contract Factory Concept. The model below describes the structure. I have problems

contract ParentA
contract ChildAA is ParentA
contract ChildBB is ParentA

contract ParentB
contract ChildCC is ParentB
contract ChildDD is ParentB

contract FactoryXX {Creates Contracts of Type ChildAA and ChildBB, and maintains a Map of all the contracts generated as State Variables}
contract FactoryYY {Creates Contracts of Type ChildCC and ChildDD, and maintains a Map of all the contracts generated}

I had a couple of questions on the deployment of such a structure in Remix and test it out:

  1. How to deploy the contracts in Remix so that I can access all the functions of both the Factory contracts. Do I have to deploy each contract separately? They are all connected.
  2. Is there a concept of a "Main" - that can tie the structure together, so that I can deploy the Main contract and be able to call all functions of the Factory Contracts. Will Delegate function call help here?
1

Do I have to deploy each contract separately? They are all connected.

No, your factories should be able to deploy all of the contracts that link to them. You cannot deploy parent classes of the children from the factory however.

How to deploy the contracts in Remix so that I can access all the functions of both the Factory contracts.

Deploy you factories, then from your factories deploy the children they are designed to create. Your children should then be created in Remix, however, you may need to get the address of the contract you just created and use it to instantiate a contract instance using the At Address button in the "Run" side menu.

I recommend using the Javascript VM over injected Web3 for this because in the JS VM, returning a contract will simply return the address, however, it will not do this in Injected Web3 due to the internal transaction that is made when your contract creates another contract. For Web3, returning a created contract just returns transaction details.

Is there a concept of a "Main" - that can tie the structure together, so that I can deploy the Main contract and be able to call all functions of the Factory Contracts.

You could have a Main contract that creates and stores both factories, but why not just merge both factories together then? Your MainFactory could create all of the children instead of having two factories each creating two types of children.

  • Thanks, @AlecKriebel. Your comments were very helpful. – userDSSR Oct 4 '17 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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