Overview
Hooks are smart contracts that extend your Gotchipus’s behavior. This guide walks you through building, deploying, and attaching a custom Hook.Prerequisites
- Solidity development experience
- Foundry installed (
forge,cast) - Familiarity with the Hooks concept
Step 1: Choose Your Hook Type
TheBaseHook contract provides three specialized base contracts:
Choose based on when your logic needs to run.
Step 2: Write Your Hook
Hook Parameters
Every Hook receives aHookParams struct:
Return Value
Hooks must returnHOOK_SUCCESS (bytes4) to indicate successful execution. Returning any other value or reverting will cause the execution to fail.
Step 3: Deploy
Step 4: Attach to a Gotchipus
Once deployed, attach your Hook via theHooksFacet:
Step 5: Test
Write Foundry tests to verify your Hook behaves correctly:Constraints
- Maximum 10 Hooks per event per Gotchipus
- Hooks must be valid contracts implementing the correct interface
- The
onlyGotchipusmodifier ensures Hooks can only be called by the Diamond - Hooks should be gas-efficient — excessive gas usage impacts execution cost
Example Hooks
The codebase includes two reference implementations:
Study these as patterns for your own Hooks.