@zilliqa-js/subscriptions
v3.5.0
Published
Class(es) for interactiong with websocket API of Zilliqa node
Downloads
3,037
Keywords
Readme
@zilliqa-js/subscriptions
JavaScript library for managing and handling subscription-based events with the Zilliqa blockchain.
Table of Contents
Installation
npm install @zilliqa-js/subscriptions --save
or
yarn add @zilliqa-js/subscriptions
Usage
To start using the subscriptions package, first import the necessary components:
const { SubscriptionBuilder, Zilliqa } = require("@zilliqa-js/subscriptions");
or using ES6 imports:
import { SubscriptionBuilder, Zilliqa } from "@zilliqa-js/subscriptions";
Examples
Subscribe to New Blocks
const zilliqa = new Zilliqa("https://api.zilliqa.com");
const subscription = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions();
subscription.subscribe();
subscription.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
console.log("New block:", event.value);
});
Unsubscribing
After subscribing, you can also unsubscribe from events:
subscription.unsubscribe();
Supported Events
- New Block Subscriptions (
SUBSCRIBE_NEW_BLOCK
) - Transaction Subscriptions (
SUBSCRIBE_TX
) - [Add more supported events as per the library]
Documentation
For comprehensive documentation, please refer to Zilliqa Official Documentation.
License
This project is licensed under the GPL License. View LICENSE for more information.