An intuitive and lightweight Typescript/Javascript client library for the Verus Coin ZMQ messaging.
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.
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 address127.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 |
---|---|
~/.komodo/VRSC |
|
/Users//Library/Application Support/komodo/VRSC |
|
%AppData%\Komodo\VRSC\ |
This is applicable for Verus
and PBaaS
blockchains.
- Update the configuration file (see below).
- Restart the node.
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 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, inLinux
, can be found in~/.verus/pbaas/<pabaas_chain_id>/<pabaas_chain_id>.conf
To install, you can use npm:
npm install verus-zmq-client
import {
EventData,
SubscriptionEventsHandler,
SubscriptionTopics,
VerusZmqClient,
VerusZmqConnection,
VerusZmqOptions
} from 'verus-zmq-client';
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()
Main client class for connecting to the Verus node ZMQ server.
Name | Usage |
---|---|
connect |
connects to the Verus ZMQ server |
listen |
starts listening to the stream of events |
disconnect |
disconnects from the Verus ZMQ server |
Main configuration class of the VerusZmqClient
class.
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 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
andafter
events can be think of like the following.
before
βonRawTxReceived
βafter
before
βonHashTxReceived
βafter
before
βonRawBlockReceived
βafter
before
βonHashBlockReceived
βafter
For any issues or inquiries, you can raise a PR or contact me at
Contacts | - |
---|---|
Pangz#4102 |
|
pangz.lab@gmail.com |
|
@PangzLab |
- Verus : https://verus.io/
- Verus Wiki : https://wiki.verus.io/#!index.md
- Bitcoin ZMQ : https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md
This library is released under the MIT License.
Creating and maintaining a high-quality library is a labor of love that takes countless hours of coding, debugging, and community interaction. If this library has made your development easier, saved you time, or added value to your projects, consider supporting its ongoing growth and maintenance. Your contributions directly help keep this project alive, up-to-date, and evolving.
Every donation, no matter the size, goes a long way in motivating the developer to dedicate time and energy to improving the library. With your support, We can continue fixing bugs, adding new features, and providing documentation and support for the community. By donating, youβre not just saying βthank youβ for the work done so farβyouβre investing in the library's future and helping it remain a reliable tool for developers worldwide.
Letβs make this library even better, together! Consider donating to show your appreciation and ensure the continued development of this project. Your generosity fuels innovation and sustains the open-source ecosystem we all benefit from. Thank you for your support! π»
Verus ID :
pangz@
VRSC :
RNrhRTq8ioDTrANrm52c9MfFyPKr3cmhBj
vARRR : RWCNjDd2HNRbJMdsYxN8ZDqyrS9fYNANaR
vDEX : RWCNjDd2HNRbJMdsYxN8ZDqyrS9fYNANaR
KMD : RWCNjDd2HNRbJMdsYxN8ZDqyrS9fYNANaR
BTC : 3MsmELpB8bsYvFJCYKrUpMuoBATVR5eeta
ETH : 0xa248d188725c3b78af7e7e8cf4cfb8469e46cf3b