Skip to main content
Wrong code edited
Source Link
Masoud jt
  • 761
  • 2
  • 7
  • 20

I have seen two ways to assign the creator of the contract. The first way is this way which you don't put the assignment in the constructor function.

pragma solidity ^0.6.6;

contract Test {
   address creator = msg.sender;
   
   constructor() public {}
}

The second way is when you assign the creator inside the constructor function

pragma solidity ^0.6.6;

contract Test {

   constructor() public {
       address creator = msg.sender;
   }
}

Is there any difference between these two? which one is better? and why?

EDIT : i wrote the second code in a totally wrong way. i meant this code

pragma solidity ^0.6.6;

contract Test {
   address creator;

   constructor() public{
       creator = msg.sender;
   }
}

I have seen two ways to assign the creator of the contract. The first way is this way which you don't put the assignment in the constructor function.

pragma solidity ^0.6.6;

contract Test {
   address creator = msg.sender;
   
   constructor() public {}
}

The second way is when you assign the creator inside the constructor function

pragma solidity ^0.6.6;

contract Test {

   constructor() public {
       address creator = msg.sender;
   }
}

Is there any difference between these two? which one is better? and why?

I have seen two ways to assign the creator of the contract. The first way is this way which you don't put the assignment in the constructor function.

pragma solidity ^0.6.6;

contract Test {
   address creator = msg.sender;
   
   constructor() public {}
}

The second way is when you assign the creator inside the constructor function

pragma solidity ^0.6.6;

contract Test {

   constructor() public {
       address creator = msg.sender;
   }
}

Is there any difference between these two? which one is better? and why?

EDIT : i wrote the second code in a totally wrong way. i meant this code

pragma solidity ^0.6.6;

contract Test {
   address creator;

   constructor() public{
       creator = msg.sender;
   }
}
Source Link
Masoud jt
  • 761
  • 2
  • 7
  • 20

Initializing the creator of a contract

I have seen two ways to assign the creator of the contract. The first way is this way which you don't put the assignment in the constructor function.

pragma solidity ^0.6.6;

contract Test {
   address creator = msg.sender;
   
   constructor() public {}
}

The second way is when you assign the creator inside the constructor function

pragma solidity ^0.6.6;

contract Test {

   constructor() public {
       address creator = msg.sender;
   }
}

Is there any difference between these two? which one is better? and why?