until now I have set the owner in a contract like so:

pragma solidity ^0.5.2;

contract SampleContract{

     address payable owner = msg.sender;


in the docs it is suggested to do it this way:

pragma solidity ^0.5.2;

contract SampleContract{

     address payable owner;

     constructor() public {
         owner = msg.sender;


I don't notice any difference in the behavior of the contract. Are both ways equivalent or is there a possible security issue with the first one?

Thanks a lot


No, at the moment both of them work properly.

You can even write something like:

address payable owner = 0xfea...0e1;

when you know who should be the owner before deployment... that is absolutely normal.

In theory using the hard coded version, both with the msg.sender or the 0x... versions, someone (an optimizer?) should try to be convinced that they are constant elements and not variables, but at the moment the solidity compiler seems not so worried about that.

  • You are welcome – Rick Park Jan 17 '19 at 22:46

No you are fine. A constructor is a function that gets called only once when the contract launches. Both produce the same results.


Although it sounds like it might imply special status, owner is merely an address. Nothing more. Nothing special.

It only receives "special" status when the contract is coded as such. For example:

modifier onlyOwner {
  require(msg.sender == owner);

function sensitiveRestrictedFunction() public onlyOwner ...

You can even set it to something new:

function changeOwner(address newOwner) public onlyOwner ...
  require(newOwner != address(0));
  owner = newOwner;

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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