Skip to main content
Checks whether calldata matches a specific function selector. Convenient helper for routing and filtering transactions.

Signature

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

Selector Formats

Accepts multiple input formats:

Use Cases

Transaction Filtering

Multi-Selector Matching

Access Control

Event Handler Selection

Performance

Constant-time comparison (4-byte check):

Comparison with Manual Check

Advantages:
  • Clear intent
  • Handles multiple selector formats
  • Optimized implementation
  • Type-safe
Use hasSelector for cleaner, faster code.

Constant-Time Comparison

Implementation uses constant-time comparison to prevent timing attacks:
Early returns would leak timing information about which byte differs.

Type Safety

Enforces CallData type at compile time: