Hello,
I generated a contract using the Wizard. The initialize function of the contract calls
__AccessControl_init();
__UUPSUpgradeable_init();
I have 3 simple questions
:
-
The __AccessControl_init() , __UUPSUpgradeable_init() are empty in version 5.0.1 , which means I really don't need to call them. Is this correct ?
-
Why is XXX_init() used and not XXX_init_unchained, is it because they are empty and don't have parents? For these 2 contracts could I use XXX_init_unchained and it will make no difference ?
-
Assuming that AccessControlUpgradeable and UUPSUpgradeable have a shared parent that must be initialized.
- Must I initialize that parent contract manually calling its _init() method. After that I can call __AccessControl_init_unchained() and __UUPSUpgradeable_init_unchained()
- Or Could I call
__UUPSUpgradeable_init() which will initialize the parent and then call AccessControll_init_unchained() because the parent is already initialized by the first call ?
Thank you very much ![]()
Code to reproduce
The code was generated using the Wizard
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract MyContract is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(address defaultAdmin, address upgrader)
initializer public
{
__AccessControl_init();
__UUPSUpgradeable_init();
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_grantRole(UPGRADER_ROLE, upgrader);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyRole(UPGRADER_ROLE)
override
{}
}
Environment
Any