splix / polkaj

Library to access and build for Polkadot using Java
Apache License 2.0
61 stars 54 forks source link
java polkadot

= PolkaJ - Polkadot Java Client :lib-version: 0.3.0 :lib-version-dev: 0.5.0-SNAPSHOT

image:https://github.com/emeraldpay/polkaj/workflows/Tests/badge.svg["Unit Tests"] image:https://codecov.io/gh/emeraldpay/polkaj/branch/master/graph/badge.svg["Coverage",link="https://codecov.io/gh/emeraldpay/polkaj"] image:https://img.shields.io/github/license/emeraldpay/polkaj.svg?style=flat-square&maxAge=2592000["License",link="https://github.com/emeraldpay/polkaj/blob/master/LICENSE"] image:https://badges.gitter.im/emeraldpay/community.svg["Gitter",link="https://gitter.im/emeraldpay/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge"]

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

WARNING: UNDER DEVELOPMENT

== Modules

== 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 [source,groovy,subs="attributes"]

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:{lib-version}' }

== Documentation

See link:docs/[Documentation] in ./docs directory, and a demonstration in ./examples.

== Example

.Show current finalized block [source,java]

PolkadotHttpApi client = PolkadotApi.newBuilder() .rpcCallAdapter(JavaHttpAdapter.newBuilder().build()) .build(); Future hashFuture = client.execute( PolkadotApi.commands().getFinalizedHead() );

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

Future 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.