Skip to main content

Overview

You can build custom hooks for specialized tracking beyond what the built-in hooks provide. Use the IHook interface and extend BaseHook for operator access control.

IHook interface

data is forwarded verbatim from the action call (signatures, proofs, attestations). Subclasses ignore parameters they do not need.

Extending BaseHook

Extend BaseHook and call _verifyAndHash(paymentInfo) to enforce caller and payment-existence checks:
authorizedCodehash is the runtime codehash of an optional trusted caller (e.g. HookCombinator). Pass bytes32(0) to gate solely on msg.sender == paymentInfo.operator.

Example: CaptureCountHook

Tracks the number and total amount of captures per payment:

Testing

Test custom hooks with Forge:

Security Checklist

  • Extends BaseHook and uses _verifyAndHash for caller and payment-existence checks
  • Returns early instead of reverting on business-logic edge cases (a reverting hook permanently bricks the surrounding action)
  • Gas-efficient storage layout
  • Full test coverage across the public surface
Unlike conditions, hooks do mutate state. BaseHook._verifyAndHash enforces msg.sender == paymentInfo.operator (or matches AUTHORIZED_CODEHASH) plus payment existence in escrow. Calling _verifyAndHash is mandatory.

Next Steps

Hooks Overview

Compare recording strategies.

Custom Conditions

Build custom condition contracts.