Roadmap › Solidity & Smart Contract Development › Module: Language Basics
Lessons in this course (11)
2. Functions: visibility, state mutability and modifiers
Basic★ Must knowLesson 2 of 11
| Visibility | Callable from |
|---|---|
public | Anywhere (internally and externally); public state vars get getters |
external | Only from outside (other contracts/EOAs), or this.f() |
internal | This contract and derived contracts (default for state variables) |
private | Only this contract (still visible on-chain — not secret!) |
| Mutability | Meaning |
|---|---|
| (none) | Can read and modify state |
view | Reads state, doesn't modify |
pure | Neither reads nor modifies state |
payable | Can receive Ether |
solidity
function quote(uint256 qty) public view returns (uint256 price) { price = qty * unitPrice; }
function add(uint256 a, uint256 b) external pure returns (uint256) { return a + b; }
receive() external payable { } // plain Ether transfers (empty calldata)
fallback() external payable { } // unknown function selector (or Ether with data)Modifiers wrap function logic (access control, state checks, reentrancy guard). Function overloading is allowed. Calls to view/pure functions from off-chain (eth_call) are free; when called inside a transaction they still cost gas.