- Published on
Solidity Expression Default Visibility and Applicable Modifiers
- Authors
- Name
- Yair Mark
- @yairmark
One of the things that frustrated me when I first started working with Solidity was not knowing for sure what the default visibility was for an expression as well as what visibility modifiers were available.
This information is in the documentation but a table detailing this information is always more succinct. To make this easier for others in future I have created just such a table below:
Expression | Default Visibility | Applicable Visibility |
---|---|---|
function | public | public / internal / private / external |
constructor | public | public / internal / private / external |
variable | internal | public / internal / private |
event | Not applicable | This is always public |
References for Visibility Modifiers
The reference for the above visibility and modifiers can be found here in the documentation:
Functions can be specified as being external, public, internal or private, where the default is public. For state variables, external is not possible and the default is internal.
No mention is made of constructor visibility but constructors are simply functions named constructor
which are called once as can be seen here:
When a contract is created, its constructor (a function declared with the constructor keyword) is executed once.
Events are not mentioned at all in the visibility section which makes sense as events are broadcast when fired meaning they cannot be anything other than public.