Skip to main content

Using Polkadot-API (PAPI)

ReactiveDOT is designed as a convenient layer over PAPI for enhanced developer quality of life. For more advanced use cases and data manipulation, it's recommended to use PAPI directly. You can access PAPI APIs through two hooks: useClient and useTypedApi.

Polkadot client

PolkadotClient interface shapes the top-level API for polkadot-api. You can find the full documentation here.

import { useClient } from "@reactive-dot/react";

function Component() {
const client = useClient();

useEffect(() => {
client._request<string>("system_version", []).then(console.log);
}, [client]);
}

Typed API

The TypedApi allows easy interaction with the runtime metadata, with a great developer experience. You can find the full documentation here.

import { useTypedApi } from "@reactive-dot/react";

function Component() {
const typedApi = useTypedApi();

useEffect(() => {
typedApi.event.Balances.Burned.watch(({ amount }) => amount > 10n ** 10n)
.pipe(take(5))
.forEach(console.log);
}, [typedApi]);
}