In all the tutorials I'm watching nobody specifies public, but remix presents warnings that function visibility has not been specified, and public is assumed.

Since I don't like warnings if possible, I am specifying public where necessary, but I wonder if the constructor function itself should be public or private. It seems to me that it should be a private one, as it's called automatically by the contract itself on creation, or is my reasoning faulty?

4 Answers 4


When you are trying to compile contract with private constructor, for example this one:

pragma solidity ^0.4.15;

contract PrivateConstructor {
    string public title;

    function PrivateConstructor() private {
        title = "Private Constructor";


you receive this error:

TypeError: Constructor must be public or internal.

So looks like contract counstructor could be only public or internal.

More details here Visibility and Getters

  • 2
    When using internal: "This contract does not implement all functions and thus cannot be created."
    – Nico
    Mar 4, 2018 at 12:15
  • 3
    @Nico this might be a bit late but when using "internal" the contract gets marked as abstract, meaning it can only be used as a base contract and will fail to compile on its own. You will have to inherit the contract and implement all functions in the derived contract. If you do not implement all functions, the derived contract will also be marked abstract - giving you the same issue.
    – Bracher
    Mar 26, 2018 at 21:48

Update for Solidity ^v0.7

The constructor visibility has been removed from Solidity. You have to remove the "public" and the "internal" modifiers from your constructors.

Read more about this in the breaking changes list.


A constructor can be internal or public; however, if the constructor has a 'payable' modifier, then the constructor can only be public.

Regarding internal visibility, it makes it possible for an abstract contract to have a constructor.


Hey after solidity compiler versions 0.7.0 the use of public and internal keywords for specifying the visibility of the constructor is deprecated. You can check this question out from StackOverflow.

  • If you consider another question has the correct answer for this question, you can vote to close this question as a duplicate Jun 26, 2022 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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