Skip to content
JavaScript SDK for CKB
Branch: develop
Clone or download
Keith-CY Merge pull request #224 from nervosnetwork/dependabot/npm_and_yarn/@t…

chore(deps-dev): bump @types/node from 12.0.0 to 12.0.2
Latest commit c1be888 May 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
packages v0.12.1 May 20, 2019
.editorconfig chore(eslint): update typescript-eslint Feb 3, 2019
.eslintrc.js refactor(rpc): fix cast and use real blockchain for testing May 9, 2019
.gitignore ci: ignore package-lock.json for deploy docs May 14, 2019
.gitmodules feat(account): remove all udt scripts Mar 20, 2019
.travis.yml ci: keep temp dir for building docs on deploy gh-pages May 14, 2019 chore: update packages' versions and changelogs May 17, 2019
LICENSE Update MIT License Jan 7, 2019 docs: update the docs about generating priv key[skip ci] May 20, 2019
makefile test: add test coverage May 7, 2019
package.json ci(docs): add docs deployment in ci May 8, 2019
tsconfig.json test: add test coverage May 7, 2019
yarn.lock Merge pull request #224 from nervosnetwork/dependabot/npm_and_yarn/@t… May 22, 2019

CKB SDK JavaScript

Service Master Develop
Travis Build Status Build Status
Coverage Codecov Codecov

NPM Telegram Group License

JavaScript SDK for Nervos CKB.



@nervosnetwork/ckb-sdk-core is the SDK used to interact with Nervos CKB, which is an open source project of public blockchain.

Before everything

Due to safety concern, the SDK won’t generate private keys for you. You can use openssl to generate a private key:

$ openssl rand 32 -hex

For other cases, say, you're going to generate it in a JavaScript Project(Please don't), Elliptic may be the one you can use.

About Nervos CKB

Nervos CKB is the layer 1 of Nervos Network, a public blockchain with PoW and cell model.

Nervos project defines a suite of scalable and interoperable blockchain protocols. Nervos CKB uses those protocols to create a self-evolving distributed network with a novel economic model, data model and more.

Notice: The ckb process will send stack trace to sentry on Rust panics. This is enabled by default before mainnet, which can be opted out by setting the option dsn to empty in the config file.

About @nervosnetwork/ckb-sdk-core

@nervosnetwork/ckb-sdk-core is an SDK implemented by JavaScript, and published in NPM Registry, which provides APIs for developers to send requests to the CKB blockchain.

This SDK can be used both in Browsers and Node.js as it's source code is implemented by TypeScript, which is a superset of JavaScript and compiled into ES6. For some browsers that have old versions, some polyfills might be injected.


We are going to use yarn for the next steps, which is similar to npm, so feel free to pick one.

For the developers who are interested in contribution.


$ yarn add @nervosnetwork/ckb-sdk-core # install the SDK into your project


This SDK includes several modules:

Address Code

Used to create an address object, whose value is the address we are going to use.

Default address algorithm is the pubkeyToAddress in utils module, which generates address in bech32 format.

Default rule to generate the address from a public key is:

  • Blake160(public key): blake2b(public key) then trauncate it for fist 20 bytes.
  • Specify options used: Address Type, Address Bin Index, Prefix. The options will be explained in an RFC.
  • Bech32 the blake160ed public key with specified options: bech32Address(blake160Pubkey, {prefix, type, binIndex})
RPC Code

Used to send RPC request to the CKB, the list could be found in CKB Project

Interfaces could be found in DefaultRPC class in this module.

Utils Code

The Utils module provides useful methods for other modules.

Types Code

The Types module used to provide the type definition of CKB Components according to the CKB Project.

CKB Project compiles to the snake case convetion, which listed in the types/CKB_RPC in the RPC module.

TypeScript compiles to the PascalCase convention, which listed in this module.


All the modules above are integrated into the core module. You can find rpc and utils in the core instance.

To use the core module, you need to import it in your project and instantiate it with a node object. For now, the node object only contains one field named url, the URI of the blockchain node your are going to communicate with.

const CKBCore = require('@nervosnetwork/ckb-sdk-core').default

const nodeUrl = 'http://localhost:8114'

const core = new CKBCore(nodeUrl)

After that you can use the core object to generate addresses, send requests, etc.


Please see Default RPC


  1. RPC Errors

The rpc module will throw an error when the result contains an error field, you need to handle it manually.


  1. Send Transaction

Development Process

This project used lerna for packages management, which needs to be bootstrapped by the following steps:

$ yarn install # to install the lerna package in this project, could be skipped if the lerna has been installed globally
$ lerna bootstrap # install the depedencies and link the packages in the project
$ npm run tsc # build packages with tsc command

After the second step, namely the bootstrap, all module packages are linked together, and used as in one package.

You can’t perform that action at this time.