How to use the CLI with contracts created via a factory contract

Hey, I am new to oz and currently we are using oz in our project to upgrade the smart contract , oz is very easy and helpful to us to maintain the smart contract up to date. Also we do have factory contract where we use to create instance of smart contract through factory contract, in that scenario, Through oz we are unable to have entries of the each contract instance in .openzeppelin json file so we unable to update the each smart contract instance… where these smart contract is not directly deployed through oz CLI tool… Is there any way to make the contract created through factory could be up to date. Thanks for your time… waiting for your response…

1 Like

Hi @Srinivasan_S,

I assume you mean that your factory contract is creating upgradeable contracts (rather than non-upgradeable contracts) as per the example: Creating instances from Solidity

There is an open issue to be able to interact with an upgradeable contract created not via the CLI: https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1264

I am not aware of a way to do this currently other than interacting with the contracts directly.

Hi @abcoathup,
Thanks for your response, Yes, actually we have different factory contract not similar as shown as an example given by you. My factory contract which is creating upgradeable contracts instances (contract already upgraded through oz CLI). In future if i am making some changes to the existing upgradeable contract through CLI and creating instances out of it through factory contract Then the newly created instances should retains the old contract state data or not?

Thanks for your time.

1 Like

Hi @Srinivasan_S,

I am not sure I understand your setup.
Can you give a bit more detail on the smart contracts?

For example:

  • Upgradeable contract A that was created via the CLI.
  • Factory contract F that creates upgradeable contracts A

The CLI doesn’t currently support interacting with contracts that weren’t created by it.
So you wouldn’t be able to upgrade a contract created by the Factory using the CLI.
You could upgrade by interacting with the Proxy contract directly.

Recommend reading OpenZeppelin SDK Upgrades Pattern if you haven’t already.

Ok, let me frame it with an example,

  • I have Upgradeable contract A that was created via the CLI.
  • I have Factory contract F that creates upgradeable contracts A.

Ok cool till now everything perfect, I have created instance A1 say F -> A1

Now I am thinking to do some more changes in contract A, I have done that changes, I am sure I could upgrade it through proxy contract directly,

So my understanding here is the instance A1 which was created through Factory F cannot be upgrade further because we don’t have proxy for A1? (correct me if i am wrong)

as per the example given here

Creating instances from Solidity

could I able to upgrade the instance or not , will CLI command support in this case or not ?

Thanks for your time

1 Like

Hi @Srinivasan_S,

Assuming you are creating upgradeable contracts F -> A1 using app.create as per the example:

Then you can upgrade the logic contract that the proxy points to, but you can’t do this by the CLI as the contract wasn’t created via the CLI. You would need to interact with the contract directly e.g. write a script to interact with the contract.


Alternatively, if your factory is only creating logic contracts e.g. A a1 = new A(); then this is a non-upgradeable contract.

Hi @abcoathup,
Thanks for the clarification, I think i got the answer, also i want to do some more home work, I will get back to you for sure if I need any clarification.

Thanks for your support and time.

1 Like

Hi @Srinivasan_S,

I recommend creating some small sample contracts and trying it out to see what you can do. (I do this a lot)

Please ask all the questions that you need.

Yes, That’s what I think :slight_smile: :+1::+1:

1 Like

Hi @abcoathup, how are you? :slight_smile: By chance do we have any sample example or script to interact with the contract directly,
Thanks for our time.

1 Like

Hi @Srinivasan_S,

Not that I am aware of.

The creating instances from Solidity example is probably the best that we have currently:
https://github.com/OpenZeppelin/openzeppelin-sdk/tree/master/examples/creating-instances-from-solidity

Hi, @abcoathup
In the meantime, is there any more chance to do this solution?
so what I wanna create is like following

  • I have the upgradeable smartcontract “ContractA”
  • I have a Factory to clone the ContractA
    After deploying the Factory, I will clone the contractA. i.e it will be contractA1

I want 2 options.

  • I want to add one function in the contractA1 cloned.
  • I want to add one function in the contractA. so the Factory will create the upgraded “ContractA”.

Please help me.
thank you.