1

I am trying to create a clone from a contract that has some privileged functions and inherits from Ownable. I realized that after cloning the owner variable is zeroed, so any privileged function, such as transferOwnership, will not run.

I noticed that Ownable has a internal function _transferOwnership that is not protected by onlyOwner modifier. I thought about calling it in my initializer function.

I just want to confirm that this is the right way to do it or it has a more recommended way to achieve this.

Thanks

1 Answer 1

0

You can add a variable to your initializer to set owner on your implementation. When deploying new contracts from your factory, this variable will be used to set owner.

Or I can recommend you to use OwnableUpgradeable that includes initializers instead of constructors, initializable functions can be called only once.

https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/access/OwnableUpgradeable.sol

1
  • OwnableUpgradeable won't help here: it only sets the owner to msg.sender which happens to be the factory.
    – Syffys
    Commented Jul 20, 2022 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.