Clarification Regarding __{ContractName}_init_unchained Function

The following statement can be found at this link.

The function __{ContractName}_init_unchained (unchained) found in every contract is the initializer function minus the calls to parent initializers, and can be used to avoid the double initialization problem, but doing this manually is not recommended.

It is not clear to me if I should be using systematically __{ContractName}_init_unchained (unchained) for all the openzeppelin upgradeable solidity modules I import into my Contract, or should I be using __{ContractName}_init instead when there is no risk of initialising the same contract twice.

Also, if it is not recommended to do this manually, is there another suggested way?

Thank you. J


:computer: Environment

You should be using _init when there is no risk of initializing the same contract twice.

Depending on your contract you may be able to generate the contract or just the initializer calls using Contracts Wizard.

Other than that, unfortunately you need to write and check this manually for now. The Upgrades Plugins will soon automatically check that it was done correctly, this may be shipped about 1 month from now. You can subscribe to https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/160 for updates.

Thank you @frangio for this info. Very helpful!

1 Like