ckb_sdk_dart 0.22.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

CKB SDK Dart #

License CircleCI Platform codecov

Dart SDK for Nervos CKB

Prerequisites #

  • Dart 2.5 or later

Installation #

You should install dart firstly through Dart.

Usage #

JSONRPC #

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);
  print(block.transactions[0].outputs[0].lock.toJson());
}

Simple Wallet example #

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


main() async {
  Api api = Api("http://localhost:8114", hasLogger: false);
  String senderPrivateKey =
      "e79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3";

  AddressGenerator generator = AddressGenerator(network: Network.testnet);
  String publicKey = Key.publicKeyFromPrivate(senderPrivateKey);
  String senderAddress = generator.addressFromPublicKey(publicKey);
  List<Receiver> receivers = [
    Receiver(
        address: "ckt1qyqqtdpzfjwq7e667ktjwnv3hngrqkmwyhhqpa8dav",
        capacity: BigInt.parse("10000000000")),
    Receiver(
        address: "ckt1qyq9ngn77wagfurp29738apv738dqgrpqpssfhr0l6",
        capacity: BigInt.parse("12000000000")),
    Receiver(
        address: "ckt1qyq2pmuxkr0xwx8kp3ya2juryrygf27dregs44skek",
        capacity: BigInt.parse("15000000000"))
  ];

  String balance = (await getBalance(api, senderAddress)).toString();
  print('Receiver1:  $balance');
  String hash = await sendCapacity(api, senderPrivateKey, receivers);
  print('Transaction hash: $hash');
  Timer(Duration(seconds: 10), () async {
    String balance1 = (await getBalance(api, senderAddress)).toString();
    print('Receiver1:  $balance1');
  });
}

Development #

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

git clone https://github.com/duanyytop/ckb_sdk_dart.git
cd ckb_sdk_dart

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

dart ./example/rpc.dart       // run rpc request example, you should run a ckb node in your local
dart ./example/wallet.dart    // run simple wallet 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.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

example/main.dart

import 'package:ckb_sdk_dart/ckb_rpc.dart';
import 'package:ckb_sdk_dart/ckb_type.dart';
import 'package:ckb_sdk_dart/src/type/block.dart';

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

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

  TransactionWithStatus 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:


dependencies:
  ckb_sdk_dart: ^0.22.2

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_crypto.dart';
import 'package:ckb_sdk_dart/ckb_rpc.dart';
import 'package:ckb_sdk_dart/ckb_type.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
5
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Platform components identified in package: io.

Health issues and suggestions

Document public APIs. (-1 points)

417 out of 417 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.

Format lib/ckb_crypto.dart.

Run dartfmt to format lib/ckb_crypto.dart.

Format lib/src/rpc/rpc.dart.

Run dartfmt to format lib/src/rpc/rpc.dart.

Format lib/src/type/cell_with_status.dart.

Run dartfmt to format lib/src/type/cell_with_status.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (dio).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
bip_bech32 ^0.1.3 0.1.3
dio ^2.1.0 2.2.2 3.0.3
http ^0.12.0+2 0.12.0+2
pointycastle ^1.0.1 1.0.1
test_coverage ^0.3.0 0.3.0+1
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
cookie_jar 1.0.1
coverage 0.12.4 0.13.3
crypto 2.1.3
glob 1.1.7
http_parser 3.1.3
json_annotation 3.0.0
json_rpc_2 2.1.0
lcov 5.4.0
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pub_semver 1.4.2
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vm_service_client 0.2.6+3
web_socket_channel 1.1.0
Dev dependencies
pedantic ^1.7.0 1.8.0+1
test ^1.6.0