useClient

function useClient<TClient>(): Client<TClient>;

Reads the Kit client published by the nearest ClientProvider. Throws a SolanaError with code SOLANA_ERROR__REACT__MISSING_PROVIDER if no provider is mounted in the ancestor tree.

Defaults to the base Client shape. Callers who know a specific plugin is installed may widen the type via the generic — this is a pure cast with no runtime capability check, so reach for useClientCapability when a missing plugin should fail loudly at mount instead of surfacing later as undefined.

Type Parameters

Type ParameterDefault typeDescription
TClient extends objectobjectThe shape the client is expected to satisfy. Pure type assertion.

Returns

Client<TClient>

Example

import { ClientWithRpc, GetEpochInfoApi } from '@solana/kit';
import { useClient } from '@solana/react';
 
function ManualSend() {
    const client = useClient<ClientWithRpc<GetEpochInfoApi>>();
    return <button onClick={() => client.rpc.getEpochInfo().send()}>Fetch</button>;
}

See

On this page