UUPS Upgradeable Contracts - _disableInitializers() function

Is the _disableInitializers() function a replacement for the initializer function in the constructor in this example:

 /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

I am trying to update my code to adhere to the most current best practices before deployment and when I replace the code block above with the block shown here, I get an undeclared identifier error.

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {

My compiler is :

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.11;

After running the constructor, I I have an initialize() function that initializes parent contracts.

I inherit these contracts:

contract MyContract is

Thanks in advance for any insights!

Found my issue most likely.. am using:
"@openzeppelin/contracts-upgradeable": "^4.5.2",

Yes, _disableInitializers() is available starting in version 4.6.0. Because 4.6.0 introduced the concept of reinitializers, the _disableInitializers() function when used in the constructor prevents any future reinitialization of the implementation.

1 Like