1.2.1 • Published 7 years ago

chain-sdk v1.2.1

Weekly downloads
11
License
Apache-2.0
Repository
github
Last release
7 years ago

Chain Node.js SDK

Usage

Get the package

The Chain Node SDK is available via npm. Make sure to use the most recent version whose major and minor components (major.minor.x) match your version of Chain Core. Node 4 or greater is required.

To install, add the chain-sdk NPM module to your package.json, using a tilde range (~) and specifying the patch version:

{
  "dependencies": {
    "chain-sdk": "~1.2.0-rc.2"
  }
}

In your code

const chain = require('chain-sdk')

const client = new chain.Client()
const signer = new chain.HsmSigner()

Asynchronous Operation

There are two options for interacting with the SDK asynchronously: promises and callbacks.

With promises:

client.transactions.query({}).then(data => {
  // operate on data
  console.log(data)
})

With callbacks:

let callback = (err, data) => {
  // operate on data
  console.log(data)
}

client.transactions.query({}, callback)

Using external signers

To connect to an HSM other than the built-in MockHSM, you must create a new Connection object:

const myHsmConnection = new chain.Connection('https://myhost.dev/mockhsm', 'tokenname:tokenvalue')
signer.addKey(myKey, myHsmConnection)

Testing

To run integration tests, run an instance of Chain Core on localhost:1999. Then run:

npm test
1.2.1

7 years ago

1.2.0-rc.2

7 years ago

1.1.1

7 years ago

1.0.3

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-pre

7 years ago