LOGBOOK

HELP

Quiz Entry - updated: 2026.07.30

What is the difference between a state variable and a local variable, and how does scope decide which functions can see a variable?

A state variable is declared directly inside the contract and persists on-chain; a local variable is declared inside a function and exists only while that function runs. A variable is visible only within the curly braces it was declared in.

contract SimpleStorage {
    uint256 favoriteNumber;   // state variable: persists, contract-wide scope

    function store(uint256 _n) public {
        uint256 temp = _n + 1;  // local variable: gone when store() returns
    }
}

favoriteNumber lives in the contract's scope, so any function inside the contract can read and change it, and its value is stored permanently on the blockchain. temp is created inside store — another function cannot see it, and it vanishes once store finishes. The rule of thumb: match the curly braces. A variable is usable only by code between the same { } that enclose its declaration.

Go deeper:

From Quiz: IOTHACK / Smart Contracts & the Remix IDE | Updated: Jul 30, 2026