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

neo-js-blockchain

v0.5.0

Published

A package for running a node on the neo blockchain.

Downloads

13

Readme

Overview

The neo-js package is designed to interface with the Neo blockchain in a number of different ways that are configured by options that are used to initialize a node. A few examples of these different interaction mechanics are defined in the quickstart below as well as in the examples.

note: All blockchain events (Invocation and Deploy) use the RPC calls to interface with the blockchain unless they can be run locally (sometimes referred to as a 'test invoke')

A note on local storage

Currently this module only support MongoDB for synchronizing the blockchain. Future storage types are planning including other NoSQL databases, SQL databases, and in-memory solutions.

This module uses 'lazy caching' to improve performance when using local storage. Blocks are initially downloaded and stored in three collections (blocks, transactions, and addresses) as a result of the sync process. Upon the first request for a specific transaction (as a result of any number of the methods), the transaction will be expanded as described in Neon wallet architecture and updated in the collection. The next time the block is requested, the expanded transaction will already be available in the collection.

This mechanic is also used for address balances. Upon requesting an update for an asset balance, the transaction collection is analyzed and the asset balance is stored in an account collection along with the max block height during the calculation. Upon future requests for the asset balance, the asset collection is first queried for previous balance. The asset balance is then updated using only the new blocks since the previous calculation event.

System Recommendations

  • NodeJS 8+
  • MongoDB 3.0+

Installation

Install the package using:

$ npm install --save neo-js-blockchain

Alternatively, to access to the latest available code, you can reference to the git repository directly:

$ npm install --save CityOfZion/neo-js#develop

note: neo-js requires that MongoDB server is installed to run the instance as a full node. Installation instructions can be found in MongoDB installation manual.

Quick Start

const Neo = require('neo-js-blockchain')

To create a new blockchain instance:

// create the local node instance that will interface with the rpc methods
const nodeT = new Neo({ network: 'testnet' }) //on testnet
const nodeM = new Neo({ network: 'mainnet' }) //on mainnet

nodeT.mesh.rpc('getBlock', 1000) //get block 1000 from testnet
nodeM.mesh.rpc('getBlock', 1000) //get block 1000 from mainnet

This will create a new node instance and configure it to sync the blockchain to a 3 mongoDB collections that we define:

const options = {
  network: 'testnet',
  storage: {
    model: 'mongoDB',
    collectionNames: {
      blocks: 'b_neo_t_blocks',
      transactions: 'b_neo_t_transactions',
      addresses: 'b_neo_t_addresses'
    }
  }
}

// create the local node instance and get the local block count after 5 seconds.
const node = new Neo(options)

setTimeout(() => {
  node.storage.getBlockCount()
    .then( (res) => console.log(res) )
}, 5000)

Documentation

Documentation (incomplete) for the project can be found at:

  • http://cityofzion.io/neo-js/

Self-documented code examples are available as part of the project source code:

  • https://github.com/CityOfZion/neo-js/blob/master/examples

Contribution

neo-js always encourages community code contribution. Before contributing please read the contributor guidelines and search the issue tracker as your issue may have already been discussed or fixed. To contribute, fork neo-js, commit your changes and submit a pull request.

By contributing to neo-js, you agree that your contributions will be licensed under its MIT license.

License