@tzkt/sdk-events
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

TzKT Events SDK

Fully typed client for working with TzKT subscriptions API.
A thin wrapper on top of SignalR converting subscriptions to observables.

Install

npm i @tzkt/sdk-events

Use

Create an instance of events service specifying TzKT events endpoint.

import { EventsService } from "@tzkt/sdk-events";

const events = new EventsService({ url: "https://api.tzkt.io/v1/events", reconnect: true });

Connection is not initiated until the first request (lazy connection):

const sub = events.operations({ types: [ 'origination' ] })
    .subscribe({ next: console.log });

Events service implements subscription router internally (on TzKT your subscriptions are aggregated) hence you can always "unsubscribe" from new updates (however it does not change anything on the TzKT side, just stops firing your observer):

sub.unsubscribe();

By default events service will infinitely try to reconnect in case of drop, you can monitor current state by subscribing to status updates:

events.status()
    .subscribe({ next: console.log });

In case you need to terminate the connection you can do that (note that event service will start again in case you send a subscription request afterwards):

await events.stop();

Examples

Check out the demo app.

Readme

Keywords

none

Package Sidebar

Install

npm i @tzkt/sdk-events

Weekly Downloads

2

Version

2.2.1

License

MIT

Unpacked Size

164 kB

Total Files

27

Last publish

Collaborators

  • dmirg
  • sstark21
  • 257byte
  • m_kus