# chain-sdk

> The Official Node.js SDK for Chain Core

Latest version **1.2.1** (published 2017-05-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install chain-sdk
pnpm add chain-sdk
yarn add chain-sdk
bun add chain-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2017-05-12 |
| First published | 2017-01-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.7 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1784 |
| Author | Chain Engineering |
| Maintainers | chain-engineering |

## Links

- npm: https://www.npmjs.com/package/chain-sdk
- Repository: https://github.com/chain/chain
- Homepage: https://github.com/chain/chain/tree/main/sdk/node
- Issues: https://github.com/chain/chain/issues
- npm.io page: https://npm.io/package/chain-sdk

## Dependencies (3)

- [btoa](https://npm.io/package/btoa.md) ^1.1.2
- [uuid](https://npm.io/package/uuid.md) ~3.0.0
- [fetch-ponyfill](https://npm.io/package/fetch-ponyfill.md) ^3.0.2

## Recent versions

- 1.2.1 (latest) — 2017-05-12
- 1.2.0-rc.2 (prerelease-1.2.0-rc.2) — 2017-05-04
- 1.1.1 — 2017-04-06
- 1.0.3 — 2017-04-06
- 1.1.0 — 2017-02-24
- 1.0.2 — 2017-01-26
- 1.0.1 — 2017-01-24
- 1.0.0 — 2017-01-20
- 1.0.0-pre — 2017-01-19

## README

# Chain Node.js SDK

## Usage

### Get the package

The Chain Node SDK is available [via npm](https://www.npmjs.com/package/chain-sdk). 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
```

---
_Source: https://npm.io/package/chain-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
