llms.txt
@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs
ReactHooks

useCurrentClient

React hook to get the current Sui client instance for the active network

The useCurrentClient hook provides access to the blockchain client instance for the current network.

With the standard setup, this returns the SuiGrpcClient instance created by createClient. More generally, it returns whatever client type your dApp Kit instance creates, as long as that client implements the Sui Core API. Application code should call the concrete client's top-level methods directly.

All dApp Kit hooks must be used within components that are descendants of DAppKitProvider. Using them outside will result in an error.

Usage

import { useCurrentClient } from '@mysten/dapp-kit-react';

export function MyComponent() {
	const client = useCurrentClient();

	const handleQuery = async () => {
		const balance = await client.getBalance({
			owner: '0x...',
		});
		console.log(balance);
	};

	return <button onClick={handleQuery}>Check Balance</button>;
}

Return value

ReturnType<typeof dAppKit.getClient>;

On this page