Nervos CKB

Nervos CKB

  • Explorer
  • GitHub

›Tooling

Introduction

  • Welcome
  • What is Nervos?

Key Concepts

  • Introduction
  • Nervos Blockchain
  • Cell Model
  • Consensus
  • Economics
  • CKB-VM

Technical Concepts

  • CKB Architecture
  • Design Philosophy
  • State and Tokens
  • Script dependencies
  • Transaction Validation Lifecycle
  • CKB VM Verification Rules

Tooling

  • Introduction
  • Neuron Wallet
  • CKB-Explorer
  • ckb-sdk-js
  • ckb-sdk-ruby
  • Community Contribution
  • Useful Materials

Getting Started

  • Introduction
  • Run a CKB Mainnet Node

Development Guide

  • Introduction
  • Testnet Aggron
  • Dev Chain
  • ckb-cli
  • ckb-sdk
  • Testnet Faucet
  • CKB JSON-RPC Protocols
  • Debugging CKB script

Glossary

  • General Glossary
  • Economic Glossary
  • Technical Glossary

References

  • Troubleshooting
  • Mining Resources
  • Nervos System Design
  • Neuron Wallet Guide
  • Neuron FAQ
Edit

ckb-sdk-js

  • Github

ckb-sdk-js is an SDK implemented in JavaScript published in NPM Registry, produced by the Nervos Foundation.

ckb-sdk-js provides APIs for developers to send requests to the CKB blockchain and can be used both in-browser and Node.js because actually it is implemented in Typescript, which is a superset of JavaScript and compiled into ES6.

Please note that ckb-sdk-js is still under development and NOT production ready. You should get familiar with CKB transaction structure and RPC before using it.

ckb-sdk-js won’t generate private keys. If you want to generate private keys, you can use openssl

openssl rand 32 -hex

ckb-sdk-js includes three modules:

  • RPC module: RPC module can send RPC requests to the CKB blockchain, the list of requests can be found in the CKB Project and the interfaces could be found in DefaultRPC class in this module.
  • Utils module: The Utils module provides useful methods for other modules.
  • Types module: The Types module id used to provide the type definition of CKB Components according to the CKB Project. CKB Project complies to the snake case convention, which is listed in types/CKB_RPC in the RPC module. TypeScript complies to the PascalCase convention, which is listed in this module.

All three modules are integrated into the core module called @nervosnetwork/ckb-sdk-core

Prerequisites

Before you start using this SDK, you'll first need to install yarn on your system. There are a growing number of different ways to install Yarn. Please refer to installation documentation.

Installation

If you want to use @nervosnetwork/ckb-sdk-core, 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 you are going to communicate with.

  • Import in the project
$ yarn add @nervosnetwork/ckb-sdk-core
  • Instantiate it with a node object

  • For now, the node object only contains one field named url, the URI of the blockchain node you are going to communicate with.

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

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

const ckb = new CKB(nodeUrl)

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

Development key points

Code Examples

  1. Send Simple Transaction
  2. Send All Balance
  3. Send Transaction with multiple private key
  4. Deposit to and withdraw from Nervos DAO

Persistent Connection

If ckb-sdk-js is running in Node.js, please add httpAgent or httpsAgent to enable the persistent connection.

// HTTP Agent
const http = require('http')
const httpAgent = new http.Agent({ keepAlive: true })
ckb.rpc.setNode({ httpAgent })
// HTTPS Agent
const https = require('https')
const httpsAgent = new https.Agent({ keepAlive: true })
ckb.rpc.setNode({ httpsAgent })
Last updated on 2/26/2020
← CKB-Explorerckb-sdk-ruby →
  • Prerequisites
  • Installation
  • Development key points
    • Code Examples
    • Persistent Connection