Chapter 5 · Solidity foundations · lesson 4
Functions and visibility
10 min
Builds on Your first contract
Chapter 5 · Solidity foundations · lesson 4
10 min
Builds on Your first contract
Every function needs to say who may call it. Solidity will not guess, and getting this wrong is the second most common way contracts are drained.
public — callable by anyone, from outside or from inside the contract.external — callable only from outside. Slightly cheaper for functions
taking large arguments, because the data can stay in calldata.internal — this contract and anything inheriting from it. Not the
outside world.private — this contract only. Not even children.internal and private functions do not appear in the ABI at all. They are
not hidden as a courtesy — there is genuinely no way to address them from
outside, because the contract exposes no entry point for them.
That is a real security boundary, unlike private on a variable, which stops
other contracts reading it but hides nothing from a person with a node.
Alongside visibility, functions declare what they do to state:
view — reads state, changes nothing.pure — does not even read state.Predict
Check