Chainhook Integration
Learn how to register Chainhooks on Clarinet devnet so you can monitor smart contract events during local development.
What you'll learn
Create Chainhook predicate files for event monitoring
Register Chainhooks with Clarinet devnet
Monitor contract calls and blockchain events
Set up webhooks for real-time notifications
Quickstart
1
Create your Chainhook predicates
Create predicate files in a chainhooks/ directory alongside your contracts:
contracts/
counter.clar
chainhooks/
increment.json
decrement.json
tests/
counter.test.ts
Clarinet.toml
Example predicate for monitoring increment events:
{
"chain": "stacks",
"uuid": "increment-hook",
"name": "Increment Counter Hook",
"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 my-secret"
}
}
}
}
}2
Common patterns
Contract deployment hook
Monitor when specific contracts are deployed:
{
"chain": "stacks",
"uuid": "deploy-hook",
"name": "Contract Deploy Monitor",
"version": 1,
"networks": {
"devnet": {
"if_this": {
"scope": "contract_deployment",
"deployer": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM"
},
"then_that": {
"file_append": {
"path": "./deployments.log"
}
}
}
}
}STX transfer monitoring
Track STX transfers above a certain threshold:
{
"chain": "stacks",
"uuid": "stx-transfer-hook",
"name": "Large STX Transfer Monitor",
"version": 1,
"networks": {
"devnet": {
"if_this": {
"scope": "stx_event",
"actions": ["transfer"],
"amount_upper_bound": "1000000000000"
},
"then_that": {
"http_post": {
"url": "http://localhost:3000/api/large-transfer"
}
}
}
}
}Was this helpful?
