Function Selector Generator
Generate the 4-byte function selector from Solidity function signatures. Supports direct signature input and ABI JSON parsing.
The function signature will be normalized to transfer(address,uint256) before hashing.
Common Functions
What is a Function Selector?
A function selector is the first 4 bytes (8 hex characters) of the keccak256 hash of a function's signature. It uniquely identifies a function within a smart contract. When you call a contract function, the selector is included in the transaction calldata to tell the contract which function to execute.
Example: transfer Function
// Function signature transfer(address,uint256) // Keccak256 hash 0xa9059cbb... // Function selector (first 4 bytes) 0xa9059cbb
How is the 4-Byte Selector Calculated?
Normalize the Signature
Remove parameter names and whitespace: transfer(address to, uint256 amount) becomes transfer(address,uint256)
Compute Keccak256 Hash
Hash the normalized signature using Keccak256 (SHA-3), producing a 32-byte output.
Extract First 4 Bytes
Take the first 4 bytes of the hash and convert to hex: 0x + 8 hex characters.
Function Signature Normalization
Function signatures can contain whitespace and parameter names, but only the function name and parameter types matter for selector calculation:
// Original signature (with names and whitespace) transfer ( address to , uint256 amount ) // Normalized signature (types only) transfer(address,uint256) // This normalized form is hashed to produce the selector
Difference: Function Selector vs Event Topic0
Function Selector
First 4 bytes of keccak256 hash. Identifies which function to call in a transaction.
Event Topic0
Full 32-byte keccak256 hash. Identifies which event was emitted in logs.
