Prerequisites
- A wallet with some tokens on a supported network (Ethereum, Gnosis Chain, Arbitrum, or Base)
- Access to CoW Swap
Step 1: Decide what call to make
A hook is defined by three fields that model an Ethereum call:| Field | Description |
|---|---|
target | The contract address to call |
callData | The encoded function call data |
gasLimit | Gas needed to execute the call (paid in sell token as part of solver fees) |
Step 2: Add the hook in CoW Swap
- Navigate to CoW Swap and connect your wallet
- Open the Hook section — look for the pre/post hook controls near your order form
- Decide whether you want the call to run before (pre-hook) or after (post-hook) your swap
- Open the hook builder (the “Build your own hooks” dApp)
- Enter the three fields from Step 1:
target,callData, andgasLimit - Click “Add Pre-Hook” or “Add Post-Hook”
The call executes in the context of the HooksTrampoline contract. If your hook needs to act on tokens the user holds (e.g., staking received tokens), you’ll need CoW Shed — see Post-Hook Examples for patterns.
Step 3: Place the order
Once you’re happy with the simulation:- Select your sell token, buy token, and amount as you normally would
- Review the order — the execution fee will include the gas cost of your hook
- Place the order
Step 4: Verify the settlement
When your order is filled (usually within a few seconds to minutes):- Find the transaction hash in the order details on CoW Explorer
- Open the transaction in Etherscan or Tenderly to inspect the internal calls
- Verify that your hook executed as expected — you should see the HooksTrampoline contract making the call you specified
How solvers handle hooks
Solvers execute your hooks as part of the settlement transaction. When a solver posts a batch solution, it includes all pre- and post-hooks for the orders in that batch. This means:- Gas-less for users — hook gas costs are rolled into the solver fees, paid from your sell token
- Atomic execution — if a hook fails, the entire settlement reverts (your swap doesn’t execute either)
- Batch-level — hooks execute within the same transaction as the swap