# @hirosystems/chainhook-client

> Chainhook TypeScript client

Latest version **2.4.0** (published 2025-06-03) · Apache 2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @hirosystems/chainhook-client
pnpm add @hirosystems/chainhook-client
yarn add @hirosystems/chainhook-client
bun add @hirosystems/chainhook-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2025-06-03 |
| First published | 2023-06-02 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 548.5 KB |
| Known vulnerabilities | 0 (+16 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 161 |
| Author | Hiro Systems PBC |
| Maintainers | blockstack-devops, zone117x, rafaelcr, cohars |
| Keywords | chainhook, client, stacks, bitcoin, ordinals |

## Links

- npm: https://www.npmjs.com/package/@hirosystems/chainhook-client
- Repository: https://github.com/hirosystems/chainhook
- Homepage: https://github.com/hirosystems/chainhook#readme
- Issues: https://github.com/hirosystems/chainhook/issues
- npm.io page: https://npm.io/package/@hirosystems/chainhook-client

## Dependencies (4)

- [pino](https://npm.io/package/pino.md) ^8.11.0
- [undici](https://npm.io/package/undici.md) ^5.21.2
- [fastify](https://npm.io/package/fastify.md) ^4.15.0
- [@fastify/type-provider-typebox](https://npm.io/package/@fastify/type-provider-typebox.md) ^3.2.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.4.0 (latest) — 2025-06-03
- 2.3.0 — 2024-10-25
- 2.2.0 — 2024-10-25
- 2.1.1 — 2024-10-23
- 2.1.0 — 2024-10-23
- 2.0.0 — 2024-10-22
- 1.12.0 — 2024-08-15
- 1.11.0 — 2024-07-17
- 1.10.0 — 2024-05-14
- 1.9.0 — 2024-05-07
- 1.8.0 — 2024-04-23
- 1.7.0 — 2024-02-02
- 1.6.0 — 2024-01-23
- 1.5.0 — 2024-01-03
- 1.4.2 — 2023-11-29
- … 14 more at https://npm.io/package/@hirosystems/chainhook-client/versions

## README

# Chainhook Client

A TypeScript client library that allows you to configure and listen for fully-typed Chainhook
predicate events.

You can either create predicates and send them to a Chainhook node manually or use the included web
server helpers to handle all node interactions transparently.

## Quick Start

1. Install npm package
    ```
    npm install @hirosystems/chainhook-client
    ```

1. Create a `Predicate` object for every Chainhook event you're interested in. See the Chainhook
   [README](https://github.com/hirosystems/chainhook#readme) for more examples.
    ```typescript
    import { ServerPredicate } from "@hirosystems/chainhook-client";
    import { randomUUID } from "crypto";

    const uuid = randomUUID();
    const predicate: ServerPredicate = {
        uuid,
        name: "test",
        version: 1,
        chain: "stacks",
        networks: {
            mainnet: {
                // `then_that` will be filled in automatically.
                if_this: {
                    scope: 'block_height',
                    higher_than: 100000,
                }
            }
        }
    };
    ```

1. Create configuration objects for the local server and the Chainhook node you'll be interacting
   with
    ```typescript
    import { ServerOptions, ChainhookNodeOptions } from "@hirosystems/chainhook-client";

    // Local server options
    const opts: ServerOptions = {
        hostname: "0.0.0.0",
        port: 3000,
        auth_token: "<random_string>",
        // Configure this value to a hostname the Chainhook node can use to reach our local server.
        // e.g. http://local.server:3000
        external_base_url: "<external_base_url>"
    };

    // Chainhook node options
    const chainhook: ChainhookNodeOptions = {
        base_url: "<node_base_url>"
    };
    ```

1. Declare and start the event server
    ```typescript
    import { Payload } from "@hirosystems/chainhook-client";

    const server = new ChainhookEventObserver(opts, chainhook);
    server.start(
        [predicate],
        async (uuid: string, payload: Payload) => {
            // This handler will be called for every chainhook event received by our server
            console.log(uuid);
            console.log(payload);
        }
    )
        .catch(e => console.error(e));
    const close = async () => {
        await server.close();
    }
    process.once('SIGINT', close);
    process.once('unhandledRejection', close);
    process.once('uncaughtException', close);
    process.once('beforeExit', close);
    ```
    Make sure you close the server gracefully in the event of an error so we can de-register our
    predicates correctly from the remote Chainhook node.

## Type Definitions

This library includes type definitions for all possible Chainhook predicate configurations and event
payloads in the form of [Typebox](https://github.com/sinclairzx81/typebox) schemas. If you need to
compile or validate any of the supplied types, generate JSON schemas, etc., you can use all of
Typebox's tools to do so.

---
_Source: https://npm.io/package/@hirosystems/chainhook-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
