usePolkadotClient

Accesses a specific Dedot client instance by network ID. Returns the client, connection status, and network information. If no network ID is provided, returns the primary network's client.

Props

Name
Type
Description

networkId

NetworkId?

The network ID to get the client for. If not provided, returns the primary client.

Return Type

Name
Type
Description

client

CompatibleSubstrateApi<ChainApi> | undefined

The Dedot client instance for the specified network.

status

ClientConnectionStatus

Connection status: NotConnected, Connecting, or Connected.

network

NetworkInfo

Network information (ID, name, RPC providers, token symbol, decimals).

Basic Usage

Access primary client:

import { usePolkadotClient } from 'typink';

function ChainInfo() {
  const { client, status, network } = usePolkadotClient();

  if (status === 'Connecting') return <div>Connecting...</div>;
  if (status === 'NotConnected') return <div>Not connected</div>;

  return (
    <div>
      <p>Network: {network.name}</p>
      <p>Symbol: {network.symbol}</p>
      <p>Connected: {status === 'Connected' ? 'Yes' : 'No'}</p>
    </div>
  );
}

Access specific network client:

const { client: polkadotClient, status } = usePolkadotClient('polkadot');
const { client: kusamaClient } = usePolkadotClient('kusama');

// Use for multi-network queries
if (polkadotClient && status === 'Connected') {
  const balance = await polkadotClient.query.system.account(address);
}

Last updated

Was this helpful?