0

In the Solidity docs, it states that

Visibility has to be specified explicitly for functions defined in contracts, they do not have a default.

Yet it also says that

By default, function types are internal, so the internal keyword can be omitted.

It seems to be saying that functions have no visibility default and their function type is internal by default. But what is the difference between a function type and function visibility? I see internal and external included under both function types and function visibility within the docs.

1 Answer 1

0

There are four types of function visibility in Solidity: external , internal , private, and public.

The types described the different visibilities (external , internal , private, and public) that can be declared in a Solidity function or state variable.

The visibilities described the different accessibility (public functions can be accessed everywhere, external functions can be only accessed outside of a contract, internal functions can only be accessed within a contract or those derived from it, and private functions can only be accessed within the same contract) of these visibilities.

Although it seems to be saying that functions have no visibility default and their function type is internal by default, it is a recommended practice that you declare visibilities in all your functions in order to avoid confusion.

3
  • Oh I think I get it. There are 2 types of functions and 4 kinds of visibilities. The 2 function types are internal and external which are the different ways a function can be called. external functions are visible externally and so are public functions. A public function may be called both internally or externally.
    – J. Doe
    Oct 17, 2022 at 23:34
  • No, there are 4 types of functions and 4 kinds of visibilities. The 4 types are internal, external, public, and private. The 4 types are also internal, external, public, and private. My point is to clarify between types and visibilities, although the types and visibilities may overlap. Oct 17, 2022 at 23:41
  • I am relatively confident there are only two types of functions. In the docs, it states Function types come in two flavours - internal and external functions. I believe the different types refer to how the function may be called while visibility relates to where they are accessible.
    – J. Doe
    Oct 18, 2022 at 1:24

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.