Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation to mention _disableInitializer() #574

Closed
ericglau opened this issue May 16, 2022 · 7 comments
Closed

Update documentation to mention _disableInitializer() #574

ericglau opened this issue May 16, 2022 · 7 comments
Labels

Comments

@ericglau
Copy link
Member

ericglau commented May 16, 2022

Update https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializing_the_implementation_contract to mention that when using Contracts v4.6.0 or later, the constructor should call _disableInitializers()

@ericglau ericglau added the docs label May 16, 2022
@Amxx
Copy link
Contributor

Amxx commented May 17, 2022

Closed by #575

@Amxx Amxx closed this as completed May 17, 2022
@taochen2001
Copy link

taochen2001 commented May 18, 2022

when adding the following to a upgradeable contract, it cannot be compiled by hardhat; Can you look into this? I got compilation error DeclarationError: Undeclared identifier. It seems compiler is not recognizing the function _disableInitializers().

constructor() {
       _disableInitializers();
    }

@ericglau
Copy link
Member Author

@taochen2001 Which version of @openzeppelin/contracts-upgradeable are you using? _disableInitializers() was introduced in v4.6.0

@taochen2001
Copy link

Just checked, it is "version": "4.5.2". Shall I upgrade to v4.6.0? By the way, in the current 4.5.2 version, even if I imported the ReentrancyGuardUpgradeable.sol in my contract, nonReentrant modifier won't be recognized by the compiler (using Hardhat); not sure if this is a bug or not.

@taochen2001
Copy link

Now i upgraded to V4.6.0, but got the following error during compiling:
Error: Contract Token is not upgrade safe

contracts/Token.sol:12: Contract Token has a constructor
Define an initializer instead

@taochen2001
Copy link

It is now working after adding:
/// @Custom:oz-upgrades-unsafe-allow constructor

@gabkov
Copy link

gabkov commented Jul 6, 2023

the solution provided by @taochen2001 is the only one? seems like a workaround.

"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@openzeppelin/hardhat-upgrades": "^2.0.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants