I set a constructor in Solidity (currently 0.8.7) The code is in following

address payable owner;

constructor() public {
    owner = msg.sender;

But when i tried to compile the code, the

Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient. --> FunctionExample.sol:9:5: | 9 | constructor() public { | ^ (Relevant source part starts here and spans across multiple lines).

Could you please explain the error I have made? thank you very much


The constructor should not have visibility attribute. So just remove the public keyword.

Furthermore, you have marked your owner variable to be payable. Therefore you have to be sure that the msg.sender is of payable type. You can just cast it with payable(msg.sender) and get rid of the error, but that won't solve the issue that somehow you need to make sure that the sender can receive the native asset. Or just remove the payable keyword from the variable.

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