Register Chainhooks on devnet

Learn how to register chainhooks on devnet.

Follow these steps to register your Chainhooks on devnet using Clarinet:

Requirements

This feature requires Clarinet version 2.1.0 or higher. To upgrade or install, refer to our installation page for Clarinet.

Create your Chainhook predicates

First, within your Clarinet project, you'll need to create your Chainhook predicate files.

These should be situated in the root of your project directory. The files can either be separate or stored within a specific folder, e.g., /chainhooks in your project root directory:

counter.clar
increment.json
decrement.json
counter.test.ts
.gitignore
Clarinet.toml
package.json
tsconfig.json
vitest.config.js

For examples on how to define your predicates, refer to the scopes reference page.

Start devnet

To start devnet, run the clarinet devnet start command from the root of your project directory. Running this command will begin a local Chainhook service in the background that automatically registers your Chainhook files within the project directory against the network.

Confirm registration

Once your devnet starts, the Chainhook service initiates the registration process. You'll know that the registration of your Chainhooks was successful by checking the confirmation message in your terminal:

INFO Feb  5 15:20:07.233382 2 chainhooks registered

If you do not see this message at the top of your clarinet devnet start logs, verify that you are using clarinet version 2.1.0 or higher.

Working with chainhooks

With these steps completed, your chainhooks are ready to trigger whenever local contract actions occur. You can monitor your network activity locally, through the clarinet devnet start terminal, to confirm chainhooks execution as you further develop and test your smart contracts. When an action occurs, you should see something like this:

INFO Feb  5 15:21:07.233382 1 hooks triggered

At this point, you can verify the payload for that action depending on whether you are expecting an http_post or file_append result from your then_that configuration.