Skip to content
Ishinka edited this page May 9, 2022 · 4 revisions

API

Api provides high-level API to interact with a node in two different ways: using defined RPC's queries directly or accessing standard or user-defined Pallet and its API.

Create an Instance

Api requires an adjusted instance of ProviderInterface (follow this link to get more information about the transport).

ProviderInterface wsProvider = WsProvider.builder()
        .setEndpoint("ws://127.0.0.1:9944")
        .build();
wsProvider.connect().join();

try (DefaultApi api = Api.with(wsProvider)) {
}

Call an RPC Method

CompletableFuture<BlockHash> finalized = api.rpc().chain().getFinalizedHead();

Interact with a Pallet

SystemPallet systemPallet = api.pallet(SystemPallet.class);
CompletableFuture<BlockHash> blockHash = systemPallet
        .blockHash()
        .get(0);
Clone this wiki locally