Skip to content
Alexander Kalankhodzhaev edited this page Aug 7, 2022 · 4 revisions

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

Supplier<ProviderInterface> wsProvider = WsProvider.builder().setEndpoint("ws://127.0.0.1:9944");

try (Api api = Api.with(wsProvider).build().join()) {
}

Call an RPC Method

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

Interact with a Pallet

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