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

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.


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.


• External: These functions are accessible from other contracts and transactions. They cannot be called internally unless the this keyword is used. You need to be careful during external calls because they can involve encountering security risks, losing gas, and throwing errors.

• Public: By default, functions are public. They can be called either internally or by using messages.

With a delegate call, a contract can invoke another contract at runtime and change the values of the public variables of the contract invoked. This is another reason why you must use public and external visibility only when required. Also, all variables at the contract level should have private or internal visibility.

• Internal: Can be accessed within smart contract and also derived smart contracts. For state variables, there are only two visibility types: public and internal. The default is internal.

• Private: Private functions are only visible to the same contract they are declared in. It is more strict. Unless required, use the minimum visibilities to safeguard your code from external attacks. The private visibility only prevents other contracts from accessing or modifying information residing in the contract, but it is still visible to the whole world on the live public blockchain.