Coexist of v5 and v4 contracts

I have a OZ v4 upgradeable contract which acts as a factory.
I want to create new OZ v5 contracts to be deployed with the factory.

However, I face two problems:

  • How to use a single project for both contracts.
  • How to test the new upgraded factory with v4 with the new v5 contracts, as the factory can't be upgraded to v5.

So..., is is possible to use both v4 and v5 at the same time and specify which version I'm using on the import?

Otherwise, how can I test the upgrade of a v4 contract which has a commont flow with new v5 contracts?

No one can help me here?

Hi @sadev, sorry for the late response, I moved your question to the Solidity Support category because this is related to our contracts library.

Generally, when a major version is released (eg. 4.x - > 5.x) the library is not backwards compatible anymore. In the case of OpenZeppelin Contracts, we provided a migration guide.

You can migrate your project easily if it hasn't been deployed yet. Upgrading from 4.9.3 to 5.x is not recommended because it changes storage locations, and for the same reason I doubt you can use both versions of the library at the same time.

Learn more at our Backwards Compatibility section

How to use a single project for both contracts.

Just install 5.0 and use that one. Is there an issue with installation or backwards compatibility? Some repro steps would help.

How to test the new upgraded factory with v4 with the new v5 contracts, as the factory can't be upgraded to v5.

Can you provide the code for such a factory?

I think I didn't explain properly given your reply @ernestognw

I want to have them coexisting. For two reasons:

  • On the dapp they will coexists.
  • For my dapp, I can't start from scratch all the contracts. But I want to update some of them. So..., I need to keep the old ones upgraded but with v4 and the new ones with v5. If I want to test them together, I CAN'T.

Just install them with an alias:

npm install @openzeppelin-contracts@npm:@openzeppelin-contracts@latest
npm install @openzeppelin-contracts-4@npm:@openzeppelin-contracts@4
1 Like

Thank you! It was easier than I anticipated :slight_smile:

1 Like