Interfaces
Interfaces define separate the 'what' (function signatures) from the 'how' (implementation). They contain no state and no function bodies. They are used to call other contracts or define standards (ERC20, ERC721).
Syntax Structure
Key Components
- Boilerplate structure required by the Solc compiler.
- Placement of state variables versus functions.
Practical Implementation
Interacting with an unknown contract via an interface.
Core Concepts
ABI
Application Binary Interface. The standard way to encode data for contract calls.
Polymorphism
You can swap the `loggerAddress` for ANY contract that implements `log`, and it just works.
Mental Model
The Universal Remote
An Interface is a User Manual or a Remote Control. It has buttons labeled 'Volume Up' and 'Power'. It doesn't tell you *how* the TV works inside, but if you point it at any supported TV (contract) and press the button, it does the action.
Under the Hood
An interface call compiles to an external `CALL`. It takes the function selector (e.g., `bytes4(keccak256('transfer(address,uint256)'))`) and the encoded arguments, and sends them to the target address.
Gas Analysis
External calls are expensive.
- • Don't call interfaces in a loop.
- • Use `staticcall` (view functions) when you don't need to change state.
Security Risks
The target might not be what you think.
- ! The contract at `loggerAddress` might not actually implement `log`, causing a revert.
- ! The contract might be malicious and contain reentrancy traps.
Common Use Cases
Interactive Visualization
See exactly how the EVM handles this code in memory, storage, and the stack.
Click Run to execute the simulation
Then use the step controls to navigate