ckb_sdk_dart 0.26.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 55

CKB SDK Dart #

License Pub CircleCI Platform codecov

Dart SDK for Nervos CKB

Prerequisites #

  • Dart 2.5 or later

Installation #

You should install dart firstly through Dart.

Usage #


A simple usage example of jsonrpc request which in example/rpc.dart:

main() async {
  Api api = Api('http://localhost:8114', hasLogger: false);
  String blockHash = await api.getBlockHash('0x2');
  Block block = await api.getBlock(blockHash);

Simple Wallet example #

A simple usage example of sendTransaction which is in example/wallet.dart:

main() async {
    api = Api(NODE_URL);

    print('Before transferring, sender\'s balance: ${await getBalance(TestAddress)} CKB');

    print('Before transferring, first receiver\'s balance: ${await getBalance(ReceiveAddresses[0])} CKB');

    print('Before transferring, change address\'s balance: ${await getBalance(changeAddress)} CKB');

    var hash = await sendCapacity(receivers, changeAddress);
    print('Transaction hash: $hash');

    // waiting transaction into block, sometimes you should wait more seconds
    sleep(Duration(seconds: 30));

    print('After transferring, sender\'s balance: ${await getBalance(TestAddress)} CKB');

    print('After transferring, receiver\'s balance: ${await getBalance(ReceiveAddresses[0])} CKB');

    print('After transferring, change address\'s balance: ${await getBalance(changeAddress)} CKB');

Development #

If you want to develop by yourself, you can download this project to your local.

git clone
cd ckb_sdk_dart

pub get                       // download and install dependences
pub run test                  // run sdk unit tests

dart ./example/main.dart       // run rpc request example, you should run a ckb node in your local
dart ./example/single_key_single_sig_tx_example.dart    // run simple transaction example, you should run a ckb node in your local
dart ./example/multi_key_single_sig_tx_example.dart    // run multi keys transaction example, you should run a ckb node in your local

Features and bugs #

Please create pull requests or issues in this GitHub repo if you want to contribute new features or find bugs.

Welcome to join us. Thanks.

0.26.3 #

Features #

  • Add ckb_utils to make sdk utils to public

0.26.2 #

Refactor #

  • Format code with dartfmt

0.26.1 #

Features #

  • Update Nervos CKB transaction signature
  • Add multi keys transaction example
  • Update address generator and parser
  • Add get_capacity_by_lock_hash rpc

Refactor #

  • Update apostrophe usage according to effective dart

Docs #

  • Update readme for sending transaction usage

Breaking Changes #

Nervos CKB transaction signature is different from old versions, and this version adapt new ckb transaction signature.

0.23.3 #

  • Upgrade dio to v3.0.4

0.23.2 #

  • Update wallet example code of readme
  • Add pub icon to readme

0.23.1 #

  • Update rpc module utils convert/serializer/calculator
  • Add tests for convert/serializer/calculator

0.23.0 #

  • Add transaction fee to wallet example

0.22.2 #

  • Update description

0.22.1 #

  • Fix pub dev config

0.22.0 #

  • Implement ckb rpc request
  • Implement ckb address according to RFC
  • Implement ckb related crypto
  • Implement ckb serialization
  • Implement ckb simple wallet which includes sendTransaction and getBalance


import 'package:ckb_sdk_dart/ckb_core.dart';

void main() async {
  var api = Api('http://localhost:8114', hasLogger: true);
  var blockHash = await api.getBlockHash('0x2');
  print('blockHash: $blockHash \n');

  var block = await api.getBlock(blockHash);
  print('block: ${block.toJson()}\n');

  var tx = await api.getTransaction(block.transactions[0].hash);

  print('transaction: ${tx.toJson()}\n');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  ckb_sdk_dart: ^0.26.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:ckb_sdk_dart/ckb_addrss.dart';
import 'package:ckb_sdk_dart/ckb_core.dart';
import 'package:ckb_sdk_dart/ckb_crypto.dart';
import 'package:ckb_sdk_dart/ckb_serialization.dart';
import 'package:ckb_sdk_dart/ckb_utils.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 18, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health issues and suggestions

Document public APIs. (-1 points)

480 out of 480 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
bip_bech32 ^0.1.3 0.1.3
dio ^3.0.8 3.0.8
hex ^0.1.2 0.1.2
http ^0.12.0+4 0.12.0+4
pointycastle ^1.0.2 1.0.2
test_coverage ^0.4.0 0.4.1
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
coverage 0.13.3+3
glob 1.2.0
http_parser 3.1.3
js 0.6.1+1
json_annotation 3.0.1
lcov 5.5.0
logging 0.11.4
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
source_span 1.6.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vm_service 2.3.1
Dev dependencies
pedantic ^1.7.0 1.9.0
test ^1.6.0