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

nxt-monitor

v0.1.2

Published

A module for monitoring and interacting with the Nxt blockchain

Downloads

2

Readme

nxt-monitor

A node.js module for monitoring and interacting with the Nxt blockchain. It executes callback functions when a certain event on the blockchain occurs, e.g. a new block or specific type of transaction.

Installation

npm install nxt-monitor

Usage

See also: https://github.com/toenu23/nxt-monitor-examples

Require the module

var nxt = require('nxt-monitor');

Configure

// Connection options
var options = {
  nxt: {
    protocol: 'http',
    hostname: '127.0.0.1',
    port: '7876',
  },
};

When not provided, the connection will default to http://127.0.0.1:7876

Initialize

The initialize function is needed to set the config and start monitoring (see below).

// Initialize
nxt.init(options);

Making an API call

Making a call to the Nxt API is very simple. Use the "call" function and provide it with an object containing the request parameters. The API response will be returned as an object.

See Nxt API documentation for possible requests and responses.

// Example API Call
var query = { requestType: 'getBlockchainStatus' };
nxt.call(query, function(err, resp) {
  console.log(resp);
});

Filters and callbacks

You can add filters to the options object, which define under which circumstances your callback function is executed. All filters need at least the "callback" attribute, which is the function to be run.

The filters set in the parameter filters will be applied to transactions, while filters in blockfilters will be applied to blocks.

You can filter for any parameter returned in the block- or transaction-objects by the Nxt API. See examples/examples.js for some more examples.

The filter conditions are defined in the conditions parameter and the callback function in the callback parameter.

See Nxt API documentation for transaction types and subtypes.

// Callback to be executed when a new transaction/block matches the filter
var myCallback = function(data) {
  // data contains the transaction or block object
  console.log(data);
}

options.filters = [
  // Payments recieved by an account
  {
    conditions : [
      { key : 'type', value : 0 },
      { key : 'recipientRS', value : 'NXT-W6CT-NPDH-AAQW-HWCHA'}
    ],
    callback : myCallback
  }
];

options.blockfilters = [
  // Blocks generated by a specific account
  {
    conditions : [
      { key : 'generatorRS', value : 'NXT-TGNZ-E8VK-69EX-3L9LX' }
    ],
    callback : myCallback
  }
];

The parameters key and value must be defined. key corresponds to the key in the API response and value it its value, against which it will be compared.

value can be an array. The callback function will be triggered if any of the values matches.

If attachment is set to true, it means that the value to be checked is an attachment of a transaction. (e.g. needed for the asset ID of an asset transaction, product ID of a marketplace transaction etc.)

Comparison of strings is case-sensitive by default. Set casesensitive to false for case-insensitive comparison.

The parameter operator defines how the values are going to be compared. Currently the following options are possible:

  • equals (Default)
  • notequals
  • greater
  • greatereq
  • less
  • lesseq
  • contains
  • notcontains
  • beginswith
  • notbeginswith
  • endswith
  • notendswith
  • regex
// Any payments greater or equal to 100 NXT (10000000000 NQT)
{
  conditions : [
    { key : 'type', value : 0 },
    { key : 'amountNQT', operator : 'greatereq', value : 10000000000 }
  ],
  callback : myCallback
},

// Transfers of a specific asset
{
  conditions : [
    { key : 'type', value : 2 },
    { key : 'subtype', value : 1 },
    { key : 'asset', attachment : true, value : 12071612744977229797 }
  ],
  callback : myCallback
},