Overview
You can build custom hooks for specialized tracking beyond what the built-in hooks provide. Use theIHook 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
ExtendBaseHook 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
BaseHookand uses_verifyAndHashfor 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
Next Steps
Hooks Overview
Compare recording strategies.
Custom Conditions
Build custom condition contracts.
