Ownable should support setting the initial owner through its constructor
See original GitHub issue🧐 Motivation Currently Ownable force you to set the initial owner to be the msg sender. This brings a dependence on the account that deploy the contract, which is often not the same as the expected owner of the contract. For security it is often better to ensure the account making deployment do not have any responsibility.
it also brings issue when you need to deploy the contract through a factory where the factory become the defacto owner of the contract.
While contracts using Ownable
could call transferOwnership
this would trigger another event.
It would be better if Ownable constructor had a owner
parameter so contract using Ownable can decide whose address is going to be the initial owner
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Writing Upgradeable Contracts - OpenZeppelin Docs
Initializers. You can use your Solidity contracts with OpenZeppelin Upgrades without any modifications, except for their constructors. Due to a requirement of ...
Read more >2.2. Creating and Initializing Objects: Constructors
A Java class defines what objects of the class know (attributes) and what they can do (behaviors). Each class has constructors like World()...
Read more >Constructors (C++) | Microsoft Learn
A constructor can initialize an object that has been declared as const ... constructor is sufficient and you don't need to define your...
Read more >Default Constructor in Java – Class Constructor Example
In this article, we will talk about constructors, how to create our own constructors, and what default constructors are in Java.
Read more >Interface defining a constructor signature? - Stack Overflow
You can't. It's occasionally a pain, but you wouldn't be able to call it using normal techniques anyway. In a blog post I've...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @wighawag
This feature has already been requested multiple times. In a perfect world, solidity would support optional arguments, and we would be able to use the provided value or fallback to initializing using msg.sender. Unfortunately, overloading constructor is not yet a thing.
While the change you ask for is easy to do, and make a lot of sense, it would also be a breaking change. Any contract that uses Ownable right now (and there are many!) would not be compatible with the newer version, and this would require users to change their code. We want to avoid this, and we certainly cannot do such a change in a minor version.
We might possibly consider this for whenever we release contracts 5.0, but until then, calling
transferOwnership
in the constructor is the way to go. While it is true that there are 2 events, the 2 are consistent with the ownership logic, so they should not be to confusing for an outside observer.Its is always possible to call
_transferOwnership(admin)
in the constructor so I don’t think its that criticalBut yes, we should consider weither we want to change that for the next major.