A bi-directional and lightweight Verus Blockchain interface that enables receiving chain events and accepting request to the Verus chain. This fully supports all existing PBaaS chains.
VerusdWeb can be configured to receive real-time blockchain events as well as sending RPC request to the Verus Blockchain. This can work as a proxy-server with a straigthforward integration and minimal setup to the chain so you can run it wihout much effort.
Just setup the node and run. By default, you can access all publicly-safe rpc methods.
You're aiming to create a proxy layer over the Verus Node API that supports real-time, event-driven communication, using WebSocket for push notifications and updates from the blockchain.
The system would allow for scripts to be triggered based on specific blockchain events, offering automation or immediate action based on blockchain state changes.
Out-of-the-box support for common Verus RPC methods, allowing users to interact with these methods via both HTTP and WebSocket.
Users can define their own API endpoints to extend functionality beyond what's provided by default Verus APIs, potentially using a utility class for ease of integration with existing RPC methods.
Creating a custom API that can cache blockchain data for performance or perform additional calculations based on blockchain data like liquidity metrics or other operations that requires heavy/extra computations before the request is returned.
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 i verusd-web
import { VerusdWeb } from 'verusd-web';
- Run the
websocket
andhttp
server at the same time. - Call the supported RPC methods.
- Request can be sent thru the
websocket
orhttp
endpoints.
const vdWeb = new VerusdWeb({
daemonConfig: {
host: 'localhost',
port: 27486,
user: 'user',
password: 'password',
zmq: { host: 'localhost', port: 8900 }
},
localServerConfig: { port: 3333 },
});
try {
vdWeb.open();
} catch(e) {
console.error(`Error occurred!`);
vdWeb.close();
}
-
To test using Postman, access the following url. This enables you to receive real-time chain events.
endpoint :ws://localhost:3333/verusd/web
-
To do an RPC call to the node using
websocket
, use the following. From the client, you can send a message in the following format.
{"m": "getblock", "p": ["c084c79d1e6097d4b5e7db87c3057337f05bad85ef757446a6461402993c579c"]}
- To do an RPC call to the node using
http
, use the following. From the client, you can send a message in the following format.
endpoint :http://localhost:3333/api/v1/verusd/web
{"m": "getblock", "p": ["c084c79d1e6097d4b5e7db87c3057337f05bad85ef757446a6461402993c579c"]}
- Create a custom routes.
- Use
RpcService.sendChainRequest
to send an RPC request the chain. It's a built-in utility. - Routing feature uses
express
under the hood.
function txController(req: Request, res: Response) {
const tx = req.params.tx;
RpcService
.sendChainRequest('getrawtransaction', [ tx ])
.then((v: any) => { res.send(v) });
}
function blockController(req: Request, res: Response) {
const block = req.params.block;
RpcService
.sendChainRequest('getblock', [ block ])
.then((v: any) => { res.send(v) });
}
const vdWeb = new VerusdWeb({
daemonConfig: {
host: 'localhost',
port: 27486,
user: 'user',
password: 'password',
zmq: { host: 'localhost', port: 8900 }
},
localServerConfig: {
port: 3333,
customApiRoutes: [
{ method: 'get', apiVersion: 1, route: 'tx/:tx', controller: txController },
{ method: 'get', apiVersion: 1, route: 'block/:block', controller: blockController }
],
},
});
- Try to access from the browser.
- Request is handled by the custom function
txController
http://localhost:3333/api/v1/tx/91048ebae23b94f7542170bef4055bcf9d37c5b1206ca5db746e4a207174ab45
- Request is handled by the custom function
blockController
http://localhost:3333/api/v1/block/1233353
- Listen when a new block or transaction is emitted.
- Run a custom script when an event occur.
- Customize the data returned to the clients.
const vdWeb = new VerusdWeb({
daemonConfig: {
host: 'localhost',
port: 27486,
user: 'user',
password: 'password',
zmq: { host: 'localhost', port: 8900 }
},
localServerConfig: {
port: 3333,
},
});
vdWeb.zmq.onHashBlock(async (value: EventData, _topic?: string, _result?: Object, wsServer?: WsServer): Promise<Object> => {
console.log("[ On New Block ]");
RpcService.sendChainRequest('getblock', [value]). then((decodedBlock: any) => {
wsServer?.send(decodedBlock);
});
return value;
});
vdWeb.zmq.onHashTx(async (value: EventData, _topic?: string, _result?: Object, wsServer?: WsServer): Promise<Object> => {
console.log("[ On New Tx ]");
RpcService.sendChainRequest('getrawtransaction', [value]).then((tx) => {
RpcService.sendChainRequest('decoderawtransaction', [tx.result]). then((decodedTx: any) => {
wsServer?.send(decodedTx);
});
});
return value;
});
- Check using any
ws
client
endpoint :ws://localhost:3333/verusd/web
- Check from your console to see when an event is emitted.
wsServer?.send(v)
is run to make sure the result is returned to thewebsocket
client;- With these, data can be customized as needed.
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
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
This library is released under the MIT License.