Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

View Function

1 min read
Pronunciation
[vyoo fungk-shun]
Analogy
A view function is like looking up a phone number in a directory—it retrieves data without changing any records.
Definition
A Solidity function modifier indicating the function does not modify state, allowing it to be executed locally without a transaction.
Key Points Intro
View functions optimize read‑only calls through:
Key Points

No state writes: Cannot use `SSTORE` or emit events.

Gas-free: Called off‑chain with no gas cost.

Can read state: Allowed `SLOAD` operations.

Constant alias: Legacy synonym for `view`.

Example
``` function balanceOf(address user) external view returns (uint256) { return balances[user]; } ```
Technical Deep Dive
Marking as `view` enforces compiler checks against state mutation. Calls via `eth_call` use local EVM without gas metering. The ABI includes `stateMutability":"view"` to inform clients.
Security Warning
View functions can still consume gas when called within transactions; restrict heavy computation.
Caveat
Cannot be used to trigger on‑chain actions or events.

View Function - Related Articles

No related articles for this term.