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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ainblockchain/ain-js

v1.13.3

Published

[![npm version](https://img.shields.io/npm/v/@ainblockchain/ain-js.svg)](https://npmjs.org/package/@ainblockchain/ain-js) ![npm-downloads](https://img.shields.io/npm/dm/@ainblockchain/ain-js) ![license](https://img.shields.io/badge/license-MPL--2.0-blue)

Readme

AIN Blockchain SDK

npm version npm-downloads license

A simple library for JavaScript and TypeScript to interact with AI Network via JSON RPC API.

Installation

$ npm install @ainblockchain/ain-js

Usage

The full API of this library can be found in API document, along with code examples. The following code shows how to create a wallet account using the wallet API.

Create Wallet

const Ain = require('@ainblockchain/ain-js').default;

const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);

function main() {
  const accounts = ain.wallet.create(1);

  console.log(accounts[0]);
}

main();

// output example:
// {
//   address: '0xb2585543Cfcfb79CF73a1a14b2DfBC411913940F',
//   private_key: '...',
//   public_key: '...'
// }

Read and Write Data

const Ain = require('@ainblockchain/ain-js').default;

const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);

async function main() {
  const address = ain.wallet.addAndSetDefaultAccount('YOUR_PRIVATE_KEY');

  // write value to db
  const result = await ain.db.ref('YOUR_DATA_PATH').setValue({
    value: 'hello',
    gas_price: 500,
    timestamp: Date.now(),
    nonce: -1,
  });

  // read value from db
  const data = await ain.db.ref('YOUR_DATA_PATH').getValue();
  console.log(data);
}

main();

Rules and Owners

Rule configs validate transactions and control write permissions, while owner configs manage write access to both rules and themselves.

The following code shows how to configure a rule to allow write access for all users:

const Ain = require('@ainblockchain/ain-js').default;

const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);

async function main() {
  const address = ain.wallet.addAndSetDefaultAccount('YOUR_PRIVATE_KEY');

  // set the rule to allow write access for all users
  const result = await ain.db.ref(appPath).setRule({
    value: {
      '.rule': {
        write: true,
      },
    },
    gas_price: 500,
    timestamp: Date.now(),
    nonce: -1,
  });
}

main();

Function Call

const Ain = require('@ainblockchain/ain-js').default;

const ain = new Ain('https://testnet-api.ainetwork.ai', 'wss://testnet-event.ainetwork.ai', 0);

async function main() {
  const address = ain.wallet.addAndSetDefaultAccount('YOUR_PRIVATE_KEY');

  // trigger a function when a value is written to the data path
  const result = await ain.db.ref('YOUR_DATA_PATH').setFunction({
    value: {
      '.function': {
        YOUR_FUNCTION_ID: {
          function_type: 'REST',
          function_url: 'YOUR_FUNCTION_URL',
          function_id: 'YOUR_FUNCTION_ID',
        },
      },
    },
    gas_price: 500,
    timestamp: Date.now(),
    nonce: -1,
  });
}

main();

Documentation

Browse the documentation online:

Testing

To run tests, a local blockchain node must be running.

  1. Clone and install the AIN Blockchain:
$ git clone https://github.com/ainblockchain/ain-blockchain.git
$ cd ain-blockchain
$ npm install
  1. Start the local blockchain:
$ bash start_local_blockchain.sh
  • For event manager test cases, ensure Node 2 is started with the ENABLE_EVENT_HANDLER environment variable set to true.
  1. Run the tests:
$ npm run test
  • To update test snapshot files:
$ npm run test_snapshot

License

MPL-2.0 License.