Signature
- Namespace
- Class
Parameters
- calldata - CallData instance to check
- selector - Expected selector to match against:
string- Hex string (e.g.,"0xa9059cbb")Uint8Array- Byte array[4]u8- 4-byte tuple
Returns
boolean - true if selector matches, false otherwise
Examples
- Basic Usage
- Function Routing
- Byte Array Selector
- Class API
Selector Formats
Accepts multiple input formats:- Hex String
- Uint8Array
- Tuple
Use Cases
Transaction Filtering
Multi-Selector Matching
Access Control
Event Handler Selection
Performance
Constant-time comparison (4-byte check):Comparison with Manual Check
- Using hasSelector
- Manual Comparison
- Clear intent
- Handles multiple selector formats
- Optimized implementation
- Type-safe
hasSelector for cleaner, faster code.
Constant-Time Comparison
Implementation uses constant-time comparison to prevent timing attacks:Type Safety
Enforces CallData type at compile time:Related
- getSelector - Extract selector
- equals - Compare full calldata
- decode - Decode parameters
- Fundamentals - How selectors work

