Function Selector
The four-byte identifier derived from an EVM function signature and used to route calls to the intended function.Definition
The four-byte identifier derived from an EVM function signature and used to route calls to the intended function.Why it matters
Smart-contract concepts are essential for understanding programmable blockchain applications.How it works
When you write a functiontransfer(address to, uint256 amount), the compiler hashes transfer(address,uint256). The first four bytes of that hash become the function’s ID. When a call arrives, the EVM compares these four bytes against the selectors defined in the contract’s dispatcher to jump to the correct code location.
Real-world example
When you execute a swap on a DEX, the input data in your transaction starts with a function selector like0xa9059cbb, which identifies the transfer function.
Advantages
- Enables efficient function routing
- Provides unique identifiers for contract methods
- Crucial for cross-contract communication
Limitations
- Risk of collision with very long function signatures
- Fixed size limits function count
- Not human-readable without mapping
Common misconceptions
- Many think the function selector is the full name of the function, but it is just a short hash.
- Some believe it handles data validation, but it only handles the routing of the call.
Related knowledge
- ABI — term
- Smart Contract — term
- Solidity — term
Canonical knowledge ID:
glossary:function-selector