What is the difference between an internal/external and public/private function in solidity?
Asked Answered
C

2

6

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?

Celeski answered 3/12, 2017 at 19:19 Comment(1)
Your question may be more suited to another StackExchange site. For questions related to the blockchain, Bitcoin and other cryptocurrencies, please ask on the Bitcoin StackExchange instead. For questions specific to Ethereum, please ask on the Ethereum StackExchange instead. :)Vibratory
N
10

Here is the difference between the four keywords:

private means it's only callable from other functions inside the contract

internal is like private but can also be called by contracts that inherit from the current one

external can only be called outside the contract

public can be called anywhere, both internally and externally.

Neocolonialism answered 27/8, 2019 at 13:28 Comment(0)
J
3

In the terminology of Solidity internal/external also uses as description 'two kinds of function calls' and not only as access modifiers.

Take a look at the documentation section about 'Visibility and Getters' inside the contracts.

Since Solidity knows two kinds of function calls (internal ones that do not create an actual EVM call (also called a “message call”) and external ones that do), there are four types of visibilities for functions and state variables.

Jung answered 13/12, 2017 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.