- Tools
- Chainhooks
- Update
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
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});78await client.updateChainhook('chainhook-uuid', {9name: 'Updated chainhook name',10filters: {11events: [{ 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 first2const current = await client.getChainhook(uuid);3await client.updateChainhook('chainhook-uuid', {4filters: {5events: [6...(current.definition.filters.events ?? []),7{ type: 'contract_call', contract_identifier: 'SP...XYZ.counter' },8],9},10});1112// ❌ Bad: Will overwrite any existing events13await client.updateChainhook(uuid, {14filters: { events: { type: 'contract_call', contract_identifier: 'SP...XYZ.counter' } },15});
Update Multiple Fields
1await client.updateChainhook('chainhook-uuid', {2name: 'Updated name',3filters: { events: [{ type: 'stx_transfer', sender: 'SP...SENDER' }] },4action: { type: 'http_post', url: 'https://new-url.com/webhooks' },5options: { decode_clarity_values: true },6});78const updated = await client.getChainhook('chainhook-uuid');9console.log('Updated:', updated.definition.name);