https://github.com/duanyytop/ckb_sdk_dart
Dart SDK for CKB
https://github.com/duanyytop/ckb_sdk_dart
android blockchain ckb dart flutter ios macos sdk web
Last synced: 2 months ago
JSON representation
Dart SDK for CKB
- Host: GitHub
- URL: https://github.com/duanyytop/ckb_sdk_dart
- Owner: duanyytop
- License: mit
- Created: 2019-09-14T01:53:13.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-05-22T23:48:03.000Z (about 1 year ago)
- Last Synced: 2024-10-14T09:23:37.963Z (8 months ago)
- Topics: android, blockchain, ckb, dart, flutter, ios, macos, sdk, web
- Language: Dart
- Homepage: https://www.nervos.org
- Size: 451 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# CKB SDK Dart
[](https://github.com/nervosnetwork/ckb-sdk-java/blob/develop/LICENSE)
[](https://pub.dev/packages/ckb_sdk_dart)
[](https://circleci.com/gh/duanyytop/ckb_sdk_dart/tree/master)
[](https://github.com/duanyytop/ckb_sdk_dart/actions?query=workflow%3A%22Dart+CI%22)
[](#installation)
[](https://codecov.io/gh/duanyytop/ckb_sdk_dart)Dart SDK for [Nervos CKB](https://github.com/nervosnetwork/ckb)
## Prerequisites
- Dart 2.5 or later
## Installation
You should install dart firstly through [Dart](https://dart.dev/get-dart).
## Usage
### JSONRPC
A simple usage example of jsonrpc request which in `example/rpc.dart`:
```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`:
```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.
```shell
git clone https://github.com/duanyytop/ckb_sdk_dart.git
cd ckb_sdk_dartpub get // download and install dependence
pub run test // run sdk unit testsdart ./example/main.dart // rpc request example
dart ./example/single_key_single_sig_tx_example.dart // single key and single signature transaction
dart ./example/multi_key_single_sig_tx_example.dart // multi keys and single signature transaction
dart ./example/dao_deposit.dart // Nervos DAO deposit example
dart ./example/dao_withdraw.dart // Nervos DAO withdraw phase1 and phase2 example
dart ./example/carrot_contract.dart // simple contract(with carrot string) example
dart ./example/udt.contract.dart // simple udt contract example
```## 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.