Edit chainhooks

Modify existing chainhooks

With updateChainhook, you can adjust an existing definition without downtime: change the webhook URL, capture new events, or fine-tune configuration options as requirements evolve.

updateChainhook

Basic Update Example

1
import { ChainhooksClient, CHAINHOOKS_BASE_URL } from '@hirosystems/chainhooks-client';
2
3
const client = new ChainhooksClient({
4
baseUrl: CHAINHOOKS_BASE_URL.testnet,
5
apiKey: process.env.HIRO_API_KEY!,
6
});
7
8
await client.updateChainhook('chainhook-uuid', {
9
name: 'Updated chainhook name',
10
filters: {
11
events: [{ type: 'ft_transfer', asset_identifier: 'SP...ABC.token::usdc' }],
12
},
13
});

Add event filter (while preserving existing events)

In order to add a new event filter to an existing chainhook, you can fetch the current definition, modify it, and then update it.

1
// ✅ Good: Fetch first
2
const current = await client.getChainhook(uuid);
3
await client.updateChainhook('chainhook-uuid', {
4
filters: {
5
events: [
6
...(current.definition.filters.events ?? []),
7
{ type: 'contract_call', contract_identifier: 'SP...XYZ.counter' },
8
],
9
},
10
});
11
12
// ❌ Bad: Will overwrite any existing events
13
await client.updateChainhook(uuid, {
14
filters: { events: { type: 'contract_call', contract_identifier: 'SP...XYZ.counter' } },
15
});

Update Multiple Fields

1
await client.updateChainhook('chainhook-uuid', {
2
name: 'Updated name',
3
filters: { events: [{ type: 'stx_transfer', sender: 'SP...SENDER' }] },
4
action: { type: 'http_post', url: 'https://new-url.com/webhooks' },
5
options: { decode_clarity_values: true },
6
});
7
8
const updated = await client.getChainhook('chainhook-uuid');
9
console.log('Updated:', updated.definition.name);

Next steps

How is this guide?