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
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
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.