Solidity theorytheory 0/50 · 0%
Functions · easy

4. Functions and visibility

public, external, internal, private and how calls arrive.

A function declares parameters, visibility, optional mutability and return types.

`external` functions can only be called from outside (or via `this.f()`); `public` works both ways; `internal` is callable by this contract and inheritors; `private` only inside this contract.

function stake(uint256 amount) external { }
function _credit(address user, uint256 amount) internal { }
function rate() public view returns (uint256) { return 5; }

Prefer `external` for the user-facing surface and `internal` helpers prefixed with an underscore — it keeps the ABI small and the intent obvious.

Check your understanding

  1. 1. Which visibility means 'callable only from outside the contract'?

  2. 2. Which visibility do inheriting contracts get access to?

  3. 3. What is a common convention for internal helpers?