Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (4.1k points)

Currently reading solidity documentation: https://solidity.readthedocs.io/en/develop/types.html#function-types

By default, function types are internal, so the internal keyword can be omitted. In contrast, contract functions themselves are public by default, only when used as the name of a type, the default is internal.

This does not make sense to me. How can a function be internal and public at the same time?

I know internal means functions can only be called within the contract and external can be called outside of the contract. So to me, internal is private and external is public but the documentation makes it sound like it can be public and internal at the same time?

So what is the difference, if any, between internal/external and public/private in regards to functions?

1 Answer

0 votes
by (14.4k points)

We conclude from the paragraph that the function types are internal by default, and the contract functions are public by default. 

You can specify the type of variable that is supposed to hold a function. This can be done as: 

function (param types) {internal|external} [pure|constant|view|payable] [returns (return types)] varName; 

The variable varName can be assigned with a function that has the same type as was defined. This can happen only within another function. 

Classifiers can be defined by simple definitions as:

  • Public - Can be accessed by all contracts. 

  • External - Can be accessed externally only. 

  • Internal -  Contracts within the system and contracts deriving from them can access. 

  • Private -  Can be accessed only by authorized contracts. 

We can say that private is a subset of internal and external is a subset of public.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...