Register Chainhooks on devnet
In this guide, you'll learn how to automatically register Chainhooks on devnet using Clarinet.
What you'll learn
Prerequisites
- Clarinet version 2.1.0 or higher installed
- A Clarinet project with smart contracts
- Basic understanding of Chainhook predicates
Register Chainhooks on devnet
Create predicate files
Create your Chainhook predicate files in your Clarinet project directory. You can place them in the project root or organize them in a dedicated folder.
{"chain": "stacks","uuid": "1","name": "Increment Counter","version": 1,"networks": {"devnet": {"if_this": {"scope": "contract_call","contract_identifier": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.counter","method": "increment"},"then_that": {"http_post": {"url": "http://localhost:3000/api/increment","authorization_header": "Bearer devnet-token"}}}}}
The predicate will trigger whenever the increment
method is called on your counter contract.
Organize project structure
Structure your project with Chainhook files in a logical location. Here's a recommended project layout:
my-project/├── contracts/│ └── counter.clar├── chainhooks/│ ├── increment.json│ └── decrement.json├── tests/│ └── counter.test.ts└── Clarinet.toml
Clarinet will automatically discover predicate files in your project directory when starting devnet.
Start devnet with Chainhook registration
Launch devnet from your project root. Clarinet automatically starts a Chainhook service and registers all predicate files it finds.
$clarinet devnet start
Look for the registration confirmation in your terminal output:
Computing deployment plan✔ Deployment plan completedINFO Feb 5 15:20:07.233382 2 chainhooks registered
This message confirms your predicates are active and monitoring the local blockchain.
Verify Chainhook execution
Interact with your contracts to trigger the registered Chainhooks. Monitor the devnet terminal for execution confirmations.
$clarinet console>> (contract-call? .counter increment)
Watch the devnet terminal for triggered hooks:
INFO Feb 5 15:21:07.233382 1 hooks triggered
Your webhook endpoint or file output will receive the event payload based on your then_that
configuration.