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

Pure Function

Pronunciation
[pyoor fungk-shun]
Analogy
A pure function is like a mathematical function f(x)=x²—it always returns the same output for the same input without side effects.
Definition
A Solidity function modifier indicating the function neither reads nor writes contract state, depending only on its input parameters.
Key Points Intro
Pure functions guarantee referential transparency via:
Key Points

No state access: Disallows `SLOAD` and `SSTORE`.

No global variables: Cannot read `msg.*` or block data.

Deterministic: Same inputs always yield same outputs.

Gas-free off‑chain: Callable without gas via `eth_call`.

Example
``` function add(uint256 a, uint256 b) external pure returns (uint256) { return a + b; } ```
Technical Deep Dive
The compiler enforces no opcodes that access state or environment. Pure functions are optimized aggressively, inlined when possible. ABI marks them as `pure` in `stateMutability`.
Security Warning
Complex pure functions can still run out of gas when used in transactions; keep logic simple.
Caveat
Cannot interact with on‑chain data or other contracts.

Pure Function - Related Articles

No related articles for this term.