Web3 Dictionary Logo
Web3 Dictionary
Contribute

Categories

AllBlockchainDappsDAOsDeFiNFTsRegulationSecuritySmart ContractsTokenomicsWalletsWeb3 GamingOthers
  1. Web3 Dictionary
  2. Smart Contracts
  3. State Variable
Smart Contracts

State Variable

A variable stored permanently on the blockchain as part of a smart contract's data.

Last Updated

2026-03-19

Related Concepts

Smart ContractStorage LayoutGasEthereum Virtual Machine
Web3-Explorer Logo

Scale Blockchain Infra

AD

Smart contracts, protocol integrations, and scalable architecture for high-performance Web3 products.

See Blockchain Services

What is State Variable?

A state variable is a piece of data that a smart contract stores permanently on the blockchain. Unlike local variables that exist only during a function call, state variables persist across every transaction and function invocation.

How does State Variable work?

  1. Variables are declared in the contract with explicit types (uint256, address, bool, etc.).
  2. Each variable is assigned a storage slot in the EVM sequentially.
  3. Writing to a state variable costs gas and records the change permanently on-chain.
  4. Reading is cheaper free for view functions called off-chain.

Why does State Variable matter?

State variables are what enable contracts to track balances, ownership, and logic across time. Without them, contracts could only perform stateless, one-off calculations.

Key features of State Variable

  • Persistent across all transactions and calls
  • Writing costs gas; reading is cheap
  • Each contract has isolated storage inaccessible to others
  • Careful layout is critical for proxy upgrades

Examples of State Variable

In an ERC-20 token, balances is a state variable mapping addresses to amounts. In a DAO, votingDelay and votingPeriod track governance timelines.

In a lending protocol, totalDeposited accumulates user deposits over time.

External References

  • Solidity Documentation
  • Smart Contracts Overview