question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Reactions:6
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
Amxxcommented, Apr 23, 2021

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.

1reaction
Amxxcommented, Sep 21, 2022

Its is always possible to call _transferOwnership(admin) in the constructor so I don’t think its that critical

But yes, we should consider weither we want to change that for the next major.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found