npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

verus-zmq-client

v0.1.0-5

Published

Verus Coin Javascript/Typescript client for ZMQ messaging.

Downloads

368

Readme

Logo

Verus ZMQ Client

An intuitive and lightweight Typescript/Javascript client library for the Verus Coin ZMQ messaging.

Introduction

Verus ZMQ Client is a library that enables to receive event notification from the Verus blockchain nodes via ZeroMQ (ZMQ) messaging protocol. This library provides functionalities to subscribe to various types of blockchain data events and receive real-time updates.

Verus Coin Setup

To receive the events from the Verus blockchain, you need to enable the ZMQ setting first by adding the following lines in the VRSC.conf.

📑 Note You should have a Verus node running locally. The address 127.0.0.1:8900 will serve as the ZMQ web server to be accessed by this library. You can change it to any available ports.

| OS | Directory | |:-----:|:--------| | Linux | ~/.komodo/VRSC | | Mac | /Users//Library/Application Support/komodo/VRSC | | Windowa | %AppData%\Komodo\VRSC\ |

Steps

This is applicable for Verus and PBaaS blockchains.

  1. Update the configuration file (see below).
  2. Restart the node.

ZMQ Configuration

Copy and paste to the config file.

...
zmqpubrawblock=tcp://127.0.0.1:8900
zmqpubrawtx=tcp://127.0.0.1:8900
zmqpubhashtx=tcp://127.0.0.1:8900
zmqpubhashblock=tcp://127.0.0.1:8900

⛓ PBaaS Chain Ready

PBaaS is already supported by this library. To enable, just follow the same setup procedure. Ideally, the port should be different from the Verus node ZMQ configuration.

Take note that PBaaS chain configurations (*.conf file) are located in a directory different from Verus. For example, in Linux, can be found in ~/.verus/pbaas/<pabaas_chain_id>/<pabaas_chain_id>.conf

🔖see for more details

Installation

To install, you can use npm:

npm install verus-zmq-client

Usage

Importing the Library

import {
    EventData,
    SubscriptionEventsHandler,
    SubscriptionTopics,
    VerusZmqClient,
    VerusZmqConnection,
    VerusZmqOptions
} from 'verus-zmq-client';

Example

const eh: SubscriptionEventsHandler = {
    onRawTxReceived: function (value: EventData): Object {
        console.log("onRawTxReceived >> " + value);
        return {};
    },
    onHashTxReceived: function (value: EventData): Object {
        console.log("onHashTxReceived >> " + value);
        return {};
    },
    onRawBlockReceived: function (value: EventData): Object {
        console.log("onRawBlockReceived >> " + value);
        return {};
    },
    onHashBlockReceived: function (value: EventData): Object {
        console.log("onHashBlockReceived >> " + value);
        return {};
    },
    before: function(value: EventData, topic?: string) {
        console.log(`before value >> ${value} ${topic}`);
        return {};
    },
    after: function(value: EventData, topic?: string) {
        console.log(`after value >> ${value} ${topic}`);
    }
};

const zmqClient = new VerusZmqClient(
    new VerusZmqOptions(
        new VerusZmqConnection(
            '127.0.0.1',
            8900,
            [
                SubscriptionTopics.rawTx,
                SubscriptionTopics.hashTx,
                SubscriptionTopics.rawBlock,
                SubscriptionTopics.hashBlock,
            ],
            eh
        )
);

try {
    zmqClient
        .connect()
        .listen();
} catch (e) {
    console.error('Error: ' + e)
}

// Don't forget to disconnect
// zmqClient.disconnet()

API

VerusZmqClient Class

Main client class for connecting to the Verus node ZMQ server.

Methods

| Name | Usage | |:-----|:--------| | connect | connects to the Verus ZMQ server | | listen | starts listening to the stream of events | | disconnect | disconnects from the Verus ZMQ server |

VerusZmqOptions Class

Main configuration class of the VerusZmqClient class.

Topics

Topics are optional. Just subscribe to the topics you need by using the following SubscriptionTopics enums. | Name | Verus ZMQ Topic | |:-----|:--------| |SubscriptionTopics.rawTx| rawtx | |SubscriptionTopics.hashTx| hashtx | |SubscriptionTopics.rawBlock| rawblock | |SubscriptionTopics.hashBlock| hashblock |

Event Handlers

Event handlers are optional. They are dependent to the subscribed topics. Define the event handlers you need. | Name | Trigger | |:-----|:--------| |onRawTxReceived | ✅ notifies about all transactions, both when they are added to mempool or when a new block arrives.✅ receives the transaction information | |onHashTxReceived | ✅ notifies about all transactions, both when they are added to mempool or when a new block arrives.✅ receives the transaction information hash | |onRawBlockReceived | ✅ notifies when the chain tip is updated.✅ receives the block information | |onHashBlockReceived | ✅ notifies when the chain tip is updated.✅ receives the block information hash | |before | ✅ called before the actual ZMQ event is being handled.✅ this receives the raw message and the topic received from the chain.✅ raw means, it can either be a Buffer object or a string as it's not yet processed.✅ the return value will be passed as an optional third argument of the main events.i.e.. onRawTxReceived(value: EventData, topic?: string, beforeResult?: Object) | |after | ✅ called after the actual ZMQ main event is being handled.✅ the third parameter will be the return value of the main event called.|

📑 Note Processing of the main (on*Received), before and after events can be think of like the following.

beforeonRawTxReceivedafterbeforeonHashTxReceivedafterbeforeonRawBlockReceivedafterbeforeonHashBlockReceivedafter

Support

For any issues or inquiries, you can raise a PR or contact me at | Contacts | - | |:-----:|:--------| | Discord | Pangz#4102 | | Gmail |[email protected] | | Twitter |@Pangz55192569 |

Reference

  • Verus : https://verus.io/
  • Verus Wiki : https://wiki.verus.io/#!index.md
  • Bitcoin ZMQ : https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md

License

This library is released under the MIT License.