{"id":13652560,"url":"https://github.com/ckb-js/ckb-sdk-js","last_synced_at":"2025-04-04T10:07:18.560Z","repository":{"id":34240547,"uuid":"164384577","full_name":"ckb-js/ckb-sdk-js","owner":"ckb-js","description":"JavaScript SDK for CKB","archived":false,"fork":false,"pushed_at":"2025-02-14T08:07:13.000Z","size":5355,"stargazers_count":42,"open_issues_count":7,"forks_count":29,"subscribers_count":7,"default_branch":"develop","last_synced_at":"2025-03-23T07:02:43.577Z","etag":null,"topics":["blockchain","ckb","javascript","nervos"],"latest_commit_sha":null,"homepage":"https://www.nervos.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ckb-js.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-07T05:52:58.000Z","updated_at":"2025-02-14T08:07:17.000Z","dependencies_parsed_at":"2024-06-15T23:39:02.367Z","dependency_job_id":"d791139d-6cf8-4399-bdcf-be29d095c165","html_url":"https://github.com/ckb-js/ckb-sdk-js","commit_stats":{"total_commits":843,"total_committers":20,"mean_commits":42.15,"dds":0.2704626334519573,"last_synced_commit":"8b7dcb6bb42124989284f66ab9fa4a96cce3d0b2"},"previous_names":["nervosnetwork/ckb-sdk-js"],"tags_count":77,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckb-js%2Fckb-sdk-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckb-js%2Fckb-sdk-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckb-js%2Fckb-sdk-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckb-js%2Fckb-sdk-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ckb-js","download_url":"https://codeload.github.com/ckb-js/ckb-sdk-js/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246730271,"owners_count":20824396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","ckb","javascript","nervos"],"created_at":"2024-08-02T02:01:00.515Z","updated_at":"2025-04-04T10:07:18.530Z","avatar_url":"https://github.com/ckb-js.png","language":"JavaScript","funding_links":[],"categories":["Tools"],"sub_categories":["SDKs"],"readme":"⚠️  **This SDK is obsolete and maintained passively.**\n\n## Recommended SDK: CCC\n\nIt’s highly recommended to use the [CCC SDK](https://github.com/ckb-ecofund/ccc) as your primary development tool within the CKB ecosystem. [CCC](https://github.com/ckb-ecofund/ccc) is the latest and most robust JavaScript SDK designed to streamline and enhance your development process. By choosing [CCC](https://github.com/ckb-ecofund/ccc), you'll be leveraging the best practices and most up-to-date features available for CKB development.\n\nTo get started with [CCC](https://github.com/ckb-ecofund/ccc), follow the [installation guide](https://github.com/ckb-ecofund/ccc#installing) and explore the [documentation](https://docs.ckbccc.com/) to integrate it seamlessly into your projects.\n\n---\n\n# CKB SDK JavaScript\n\n| Service  | Master                                                                                                                                                   | Develop                                                                                                                                                    |\n| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Unit Tests   | [![Unit Tests](https://github.com/ckb-js/ckb-sdk-js/workflows/Unit%20Tests/badge.svg?branch=master)](https://github.com/ckb-js/ckb-sdk-js/actions?query=branch%3Amaster+workflow%3A%22Unit+Tests%22)                      | [![Unit Tests](https://github.com/ckb-js/ckb-sdk-js/workflows/Unit%20Tests/badge.svg?branch=develop)](https://github.com/ckb-js/ckb-sdk-js/actions?query=branch%3Adevelop+workflow%3A%22Unit+Tests%22)                       |\n| Coverage | [![Codecov](https://codecov.io/gh/ckb-js/ckb-sdk-js/branch/master/graph/badge.svg)](https://codecov.io/gh/ckb-js/ckb-sdk-js/branch/master) | [![Codecov](https://codecov.io/gh/ckb-js/ckb-sdk-js/branch/develop/graph/badge.svg)](https://codecov.io/gh/ckb-js/ckb-sdk-js/branch/develop) |\n\n[![NPM](https://img.shields.io/npm/v/@nervosnetwork/ckb-sdk-core/latest.svg)](https://www.npmjs.com/package/@nervosnetwork/ckb-sdk-core)\n[![Package Quality](https://npm.packagequality.com/shield/%40nervosnetwork%2Fckb-sdk-core.svg)](https://packagequality.com/#?package=@nervosnetwork/ckb-sdk-core)\n[![License](https://img.shields.io/npm/l/@nervosnetwork/ckb-sdk-core.svg)](./LICENSE)\n[![Telegram Group](https://cdn.rawgit.com/Patrolavia/telegram-badge/8fe3382b/chat.svg)](https://t.me/nervos_ckb_dev)\n[![SNYK](https://github.com/ckb-js/ckb-sdk-js/workflows/SNYK/badge.svg)](https://github.com/ckb-js/ckb-sdk-js/actions?query=workflow%3ASNYK)\n[![Deploy Docs](https://github.com/ckb-js/ckb-sdk-js/workflows/Deploy%20Docs/badge.svg)](https://nervosnetwork.github.io/ckb-sdk-js/classes/_nervosnetwork_ckb_sdk_core.default.html)\n\nJavaScript SDK for Nervos [CKB](https://github.com/nervosnetwork/ckb).\n\nThe ckb-sdk-js is still under development and aim for providing low-level APIs of data construction. You should get familiar with CKB transaction structure and RPCs before using it and design your own DApp SDK based on this one.\n\n\u003cdetails\u003e\n\u003csummary\u003eToC\u003c/summary\u003e\n\u003cp\u003e\n\n- [Type Doc](#typedoc)\n- [Introduction](#introduction)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Modules](#modules)\n- [CORE](#core)\n- [RPC](#rpc)\n- [Utils](#utils)\n- [Errors](#errors)\n- [Examples](#examples)\n- [Troubleshooting](#troubleshooting)\n- [Development Process](#development-process)\n\n\u003cp\u003e\n\u003c/details\u003e\n\n---\n\n# TypeDoc\n\n- [Global](https://nervosnetwork.github.io/ckb-sdk-js/index.html)\n- [Core](https://nervosnetwork.github.io/ckb-sdk-js/classes/_nervosnetwork_ckb_sdk_core.default.html)\n- [RPC](https://nervosnetwork.github.io/ckb-sdk-js/classes/_nervosnetwork_ckb_sdk_rpc.default.html)\n- [Types](https://nervosnetwork.github.io/ckb-sdk-js/modules/_nervosnetwork_ckb_types.CKBComponents.html)\n\n# Introduction\n\n`@nervosnetwork/ckb-sdk-core` is the SDK used to interact with [Nervos CKB](https://github.com/nervosnetwork/ckb), which is an open source project of public blockchain.\n\n## Before everything\n\nDue to safety concern, the SDK won’t generate private keys for you. You can use `openssl` to generate a private key:\n\n```sh\n$ openssl rand -hex 32\n```\n\nFor other cases, say, you're going to generate it in a JavaScript Project(Please don't), [Elliptic](https://github.com/indutny/elliptic/) may be the one you can use.\n\n## About Nervos CKB\n\n\u003e Nervos CKB is the layer 1 of Nervos Network, a public blockchain with PoW and cell model.\n\n\u003e 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.\n\n\u003e _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.\n\n## About @nervosnetwork/ckb-sdk-core\n\n`@nervosnetwork/ckb-sdk-core` is an SDK implemented by JavaScript, and published in [NPM Registry](https://www.npmjs.com/package/@nervosnetwork/ckb-sdk-core/), which provides APIs for developers to send requests to the CKB blockchain.\n\nThis SDK can be used both in Browsers and [Node.js](https://nodejs.org) 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.\n\n# Prerequisites\n\nWe are going to use [yarn](https://yarnpkg.com/) for the next steps, which is similar to [npm](https://npmjs.com), so feel free to pick one.\n\nFor the developers who are interested in contribution.\n\n# Installation\n\n```sh\n$ yarn add @nervosnetwork/ckb-sdk-core # install the SDK into your project\n```\n\n# Modules\n\nThis SDK includes several modules:\n\n\u003cdetails\u003e\n\u003csummary\u003e\n  RPC \u003ca href=\"https://github.com/ckb-js/ckb-sdk-js/tree/develop/packages/ckb-sdk-rpc\" alt=\"rpc\"\u003eCode\u003c/a\u003e\n\u003c/summary\u003e\n\u003cdd\u003e\n\nUsed to send RPC request to the CKB, the list could be found in [CKB Project](https://github.com/nervosnetwork/ckb/blob/develop/util/jsonrpc-types/src/blockchain.rs)\n\nInterfaces could be found in `DefaultRPC` class in this module.\n\n\u003c/dd\u003e\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\n  Utils \u003ca href=\"https://github.com/ckb-js/ckb-sdk-js/tree/develop/packages/ckb-sdk-utils\" alt=\"utils\"\u003eCode\u003c/a\u003e\n\u003c/summary\u003e\n\u003cdd\u003e\n\nThe Utils module provides useful methods for other modules.\n\n\u003c/dd\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\n  Types \u003ca href=\"https://github.com/ckb-js/ckb-sdk-js/tree/develop/packages/ckb-types\" alt=\"types\"\u003eCode\u003c/a\u003e\n\u003c/summary\u003e\n\u003cdd\u003e\n\nThe Types module used to provide the type definition of CKB Components according to the [CKB Project](https://github.com/nervosnetwork/ckb/blob/develop/util/jsonrpc-types/src/blockchain.rs).\n\nCKB Project compiles to the snake case convetion, which listed in the types/CKB_RPC in the RPC module.\n\nTypeScript compiles to the PascalCase convention, which listed in this module.\n\n\u003c/dd\u003e\n\u003c/details\u003e\n\n# CORE\n\nAll the modules above are integrated into the core module. You can find `rpc` and `utils` in the core instance.\n\nTo 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.\n\n```javascript\nconst CKB = require('@nervosnetwork/ckb-sdk-core').default\n\nconst nodeUrl = 'http://localhost:8114'\n\nconst ckb = new CKB(nodeUrl)\n```\n\nAfter that you can use the `ckb` object to generate addresses, send requests, etc.\n\n# RPC\n\n## Basic RPC\n\nPlease see [Basic RPC](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-rpc/src/Base/index.ts#L23)\n\n## Batch Request\n\n```javascript\n/**\n * The following batch includes two requests\n *   1. getBlock('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')\n *   2. getTransactionsByLockHash('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x0', '0x1)\n */\nconst batch = rpc.createBatchRequest([\n  ['getBlock', '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'],\n  ['getTransactionsByLockHash', '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x0', '0x1'],\n])\n\n/**\n * Add a request and the batch should include three requests\n *  1. getBlock('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')\n *  2. getTransactionsByLockHash('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x0', '0x1)\n *  3. getTransactionsByLockHash('0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '0x0', '0x1)\n */\nbatch.add(\n  'getTransactionsByLockHash',\n  '0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',\n  '0x0',\n  '0x1',\n)\n\n/**\n * Remove a request by index and the batch should include two requests\n *  1. getBlock('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')\n *  2. getTransactionsByLockHash('0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '0x0', '0x1)\n */\nbatch.remove(1)\n\n/**\n * Send the batch request\n */\nbatch.exec().then(console.log)\n// [\n//   { \"header\": { }, \"uncles\": [], \"transactions\": [], \"proposals\": [] },\n//   [ { \"consumedBy\": { }, \"createdBy\": { } } ]\n// ]\n\n// chaning usage\nbatch.add().remove().exec()\n```\n\n## Persistent Connection\n\nPlease add `httpAgent` or `httpsAgent` to enable the persistent connection.\n\nIf the SDK is running in Node.js, the following steps make the persistent connection available.\n\n```javascript\n// HTTP Agent\nconst http = require('http')\nconst httpAgent = new http.Agent({ keepAlive: true })\nckb.rpc.setNode({ httpAgent })\n\n// HTTPS Agent\nconst https = require('https')\nconst httpsAgent = new https.Agent({ keepAlive: true })\nckb.rpc.setNode({ httpsAgent })\n```\n\n# Utils\n\n[Most used utilities](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-utils/README.md)\n\n# Errors\n\n1. RPC Errors\n\nThe rpc module will throw an error when the result contains an error field, you need to handle it manually.\n\n# Examples\n\n1. [Send Simple Transaction](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sendSimpleTransaction.js)\n2. [Send All Balance](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sendAllBalance.js)\n3. [Send Transaction with multiple private key](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sendTransactionWithMultiplePrivateKey.js)\n4. [Deposit to and withdraw from Nervos DAO](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/nervosDAO.js)\n5. [Send Transaction with Lumos Collector](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sendTransactionWithLumosCollector.js)\n6. [SUDT](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sudt.js)\n\n# Troubleshooting\n\n## Indexer Module\n\nThe Indexer Module in CKB has been deprecated since [v0.36.0](https://github.com/nervosnetwork/ckb/releases/tag/v0.36.0), please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) or [lumos-indexer](https://github.com/nervosnetwork/lumos/tree/develop/packages/indexer) instead.\n\nA simple example [sendTransactionWithLumosCollector](https://github.com/ckb-js/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sendTransactionWithLumosCollector.js) of wokring with lumos has beed added.\n\n# Development Process\n\nThis project used [lerna](https://github.com/lerna/lerna/) for packages management, which needs to be bootstrapped by the following steps:\n\n```sh\n$ yarn add lerna --exact --ignore-workspace-root-check # to install the lerna package in this project, could be skipped if the lerna has been installed globally\n$ npx lerna bootstrap # install the depedencies and link the packages in the project\n$ yarn run tsc # build packages with tsc command\n```\n\nAfter the second step, namely the bootstrap, all module packages are linked together, and used as in one package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fckb-js%2Fckb-sdk-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fckb-js%2Fckb-sdk-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fckb-js%2Fckb-sdk-js/lists"}