/polkaj

Library to access and build for Polkadot using Java

Primary LanguageJavaApache License 2.0Apache-2.0

PolkaJ - Polkadot Java Client

Unit Tests Coverage License Gitter

Java client library to use and access API of Polkadot based networks.

Warning
UNDER DEVELOPMENT
  • Latest Stable Version: 0.3.0

  • Latest Snapshot Version: 0.4.0-SNAPSHOT

Modules

  • io.emeraldpay.polkaj:polkaj-scale:0.3.0 - SCALE codec implementation

  • io.emeraldpay.polkaj:polkaj-scale-types:0.3.0 - SCALE mapping for standard Polkadot types

  • io.emeraldpay.polkaj:polkaj-schnorrkel:0.3.0 - Schnorrkel for Java

  • io.emeraldpay.polkaj:polkaj-ss58:0.3.0 - SS58 codec to encode/decode addresses and pubkeys

  • io.emeraldpay.polkaj:polkaj-common-types:0.3.0 - common types (Address, DotAmount, Hash256, etc)

  • io.emeraldpay.polkaj:polkaj-json-types:0.3.0 - JSON RPC mapping to Java classes

  • io.emeraldpay.polkaj:polkaj-api-base:0.3.0 - RPC base classes

  • io.emeraldpay.polkaj:polkaj-api-http:0.3.0 - JSON RPC HTTP client

  • io.emeraldpay.polkaj:polkaj-api-ws:0.3.0 - JSON RPC WebSocket client

  • io.emeraldpay.polkaj:polkaj-tx:0.3.0 - Storage access and Extrinsics

Usage

To use development SNAPSHOT versions you need to install the library into the local Maven repository.

Install into local Maven
gradle install
Using with Gradle
repositories {
   // polkaj public repo
   maven { url  "https://dl.bintray.com/emerald/polkaj" }
   // required for com.github.multiformats:java-multibase library
   maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'io.emeraldpay.polkaj:polkaj-api-http:0.3.0'
}

Documentation

See Documentation in ./docs directory, and a demonstration in ./examples.

Example

Show current finalized block
PolkadotHttpApi client = PolkadotHttpApi.newBuilder().build();
Future<Hash256> hashFuture = client.execute(
        PolkadotApi.commands().getFinalizedHead()
);

Hash256 hash = hashFuture.get();
System.out.println("Current head: " + hash);

Future<BlockResponseJson> blockFuture = client.execute(
        PolkadotApi.commands().getBlock(hash)
);

BlockResponseJson block = blockFuture.get();
System.out.println("Current height: " + block.getBlock().getHeader().getNumber());
System.out.println("State hash: " + block.getBlock().getHeader().getStateRoot());


client.close();

License

The core project code is released under Apache 2.0 license.

Examples and docs are published under CC0 license + additionally Apache 2.0 for code parts in the examples.