- Tools
- Chainhooks
- Create
Create chainhooks
Create and activate chainhooks using the Chainhooks SDK
Creates a new chainhook configuration. By default, new chainhooks are created in a disabled state unless enable_on_registration is set to true.
registerChainhook
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('Chainhooks 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
1// Enable a chainhook2await client.enableChainhook('chainhook-uuid', true);34// Disable a chainhook5await 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):
1await client.bulkEnableChainhooks({2enabled: true,3filters: {4uuids: [5'uuid-1',6'uuid-2',7'uuid-3',8],9},10});
By Webhook URL
Enable all chainhooks that POST to a specific URL:
1await client.bulkEnableChainhooks({2enabled: true,3filters: {4webhook_url: 'https://example.com/webhooks',5},6});
By Status
Enable all chainhooks with a specific status:
12await client.bulkEnableChainhooks({3enabled: true,4filters: {5statuses: ['inactive'],6},7});
Combined Filters
Use multiple filters together:
1await client.bulkEnableChainhooks({2enabled: false, // Disable matching chainhooks3filters: {4webhook_url: 'https://old-server.com/webhooks',5statuses: ['active'],6},7});
This will disable all active chainhooks that POST to the old webhook URL.