Create chainhooks
Create and activate chainhooks using the Chainhook SDK
Register & Enable
Learn how to create and activate chainhooks using the Chainhook SDK.
registerChainhook
Creates a new chainhook configuration. By default, new chainhooks are created in a disabled state unless enable_on_registration is set to true.
Example
1import { ChainhooksClient, CHAINHOOKS_BASE_URL } from '@hirosystems/chainhooks-client';23const client = new ChainhooksClient({4baseUrl: CHAINHOOKS_BASE_URL.testnet,5apiKey: process.env.HIRO_API_KEY!,6});78const chainhook = await client.registerChainhook({9version: '1',10name: 'my-chainhook',11chain: 'stacks',12network: 'testnet',13filters: {14events: [15{16type: 'contract_call',17contract_identifier: 'SP...XYZ.counter',18function_name: 'increment',19},20],21},22action: {23type: 'http_post',24url: 'https://example.com/webhooks',25},26options: {27decode_clarity_values: true,28enable_on_registration: true,29},30});3132console.log('Chainhook UUID:', chainhook.uuid);33console.log('Enabled:', chainhook.status.enabled); // true
If you don't set enable_on_registration, the chainhook will be created but disabled by default.
enableChainhook
Enable or disable a single chainhook by UUID. This allows you to enable chainhooks after registration or pause without deleting it.
Examples
// Enable a chainhookawait client.enableChainhook('chainhook-uuid', true);// Disable a chainhookawait client.enableChainhook('chainhook-uuid', false);
Returns HTTP 204 No Content on success.
bulkEnableChainhooks
Enable or disable multiple chainhooks at once using filters. This is useful for managing many chainhooks programmatically.
By UUIDs
Enable specific chainhooks by their UUIDs (maximum 200):
await client.bulkEnableChainhooks({enabled: true,filters: {uuids: ['uuid-1','uuid-2','uuid-3',],},});
By Webhook URL
Enable all chainhooks that POST to a specific URL:
await client.bulkEnableChainhooks({enabled: true,filters: {webhook_url: 'https://example.com/webhooks',},});
By Status
Enable all chainhooks with a specific status:
await client.bulkEnableChainhooks({enabled: true,filters: {statuses: ['inactive'],},});
Combined Filters
Use multiple filters together:
await client.bulkEnableChainhooks({enabled: false, // Disable matching chainhooksfilters: {webhook_url: 'https://old-server.com/webhooks',statuses: ['active'],},});
This will disable all active chainhooks that POST to the old webhook URL.