Skip to content
Java SDK for CKB
Branch: develop
Clone or download
duanyytop Merge pull request #81 from nervosnetwork/master
Merge master(v0.12.0) back to develop
Latest commit 74298f1 May 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config doc: update how to develop in readme Apr 25, 2019
console refactor: refactor wallet and test case May 17, 2019
core refactor: refactor wallet and test case May 17, 2019
gradle
utils Merge pull request #74 from BaojunCZ/feat-generate-witness May 16, 2019
.gitignore chore: update type hash to lock hash Apr 1, 2019
.travis.yml add travis ci test Dec 24, 2018
CHANGELOG.md docs: update CHANGELOG for v0.12.0 May 17, 2019
LICENSE Create LICENSE Dec 21, 2018
README.md Update README.md May 8, 2019
build.gradle refactor: refactor wallet and test case May 17, 2019
gradlew Add RPC requests for ckb and add response model for http Dec 21, 2018
gradlew.bat Add RPC requests for ckb and add response model for http Dec 21, 2018
settings.gradle feat: add console module for packing Jan 25, 2019

README.md

CKB SDK Java

Build Status

Java SDK for Nervos CKB.

Prerequisites

  • Java 8
  • Gradle 5.0 or later

Installation

You can generate the jar and import manually.

git clone https://github.com/nervosnetwork/ckb-sdk-java.git
gradle shadowJar  // ./gradlew shadowJar 

A console-{version}-all.jar package will be generated, which you can put into your project to develop with it.

Usage

JSON-RPC

You can make JSON-RPC request to your CKB node URL with this SDK. Below are some examples:

CkbService ckbService = CKBService.build(new HttpService("your-ckb-node-url"));

// using RPC `get_tip_block_number`, it will return the latest block number
BigInteger blockNumber = ckbService.getTipBlockNumber().send().getBlockNumber();

// using RPC `get_block_hash` with block number as parameter, it will return block hash
String blockNumber = "0"
String blockHash = ckbService.getBlockHash(blockNumber).send().getBlockHash();

// using RPC `get_block` with block hash as parameter, it will return block object
Block block = ckbService.getBlock(blockHash).send().getBlock();

You can see more JSON-RPC requests from RPC Document

Address

You can generate ckb address through this SDK as below:

There are many address generating methods, and this is just an example.

// Generate ckb testnet address
AddressUtils utils = new AddressUtils(Network.TESTNET);

// Generate public key from private key through SECP256K1
String publicKey =
    Sign.publicKeyFromPrivate(
            Numeric.toBigInt(
                "e79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3"),
            true)
        .toString(16);

String address = utils.generate(publicKey);

Development

We use Google Java Code Format and follow Google Checkstyle for development.

If verifyGoogleJavaFormat FAILED happens when you build this project, please format your code with Google Java Code Format or execute ./gradlew goJF on macOS and Linux, or gradlew goJF on Windows.

If you use IntelliJ IDEA to develop, you can install google-java-format plugin to format code automatically.

License

The SDK is available as open source under the terms of the MIT License.

Changelog

See CHANGELOG for more information.

You can’t perform that action at this time.