Vyper theorytheory 0/50 · 0%
Storage · easy

4. Storage variables and public()

Declaring persistent state and exposing getters.

State variables are declared at module level with a name and type. Wrapping the type in `public(...)` auto-generates an external getter function, exactly like Solidity's `public` modifier.

balance: public(uint256)
owner: address
_secret: bytes32

Non-public variables are only reachable through functions you write yourself. As in Solidity, 'private' storage is not confidential — all contract storage can be read directly off chain by anyone who knows the slot layout.

Vyper has no visibility keywords like `internal`/`private` for variables; a state variable is either `public(...)` or plain (module-internal only, accessible via `self.`).

Check your understanding

  1. 1. How do you expose a getter for a state variable in Vyper?

  2. 2. Is unexposed contract storage confidential?

  3. 3. How do you access a state variable from within a function?