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

useWalletConnection

The useWalletConnection hook provides access to the current wallet connection status and information.

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

Usage

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

export function MyComponent() {
	const connection = useWalletConnection();

	if (connection.status === 'disconnected') {
		return <div>Please connect your wallet</div>;
	}

	if (connection.status === 'connecting') {
		return <div>Connecting...</div>;
	}

	// status === 'connected'
	return (
		<div>
			<p>Connected to: {connection.wallet.name}</p>
			<p>Address: {connection.account.address}</p>
		</div>
	);
}

Return Value

{
	status: 'disconnected' | 'connecting' | 'reconnecting' | 'connected';
	wallet: UiWallet | null;
	account: UiWalletAccount | null;
	supportedIntents: string[];
	isConnected: boolean;
	isConnecting: boolean;
	isReconnecting: boolean;
	isDisconnected: boolean;
}

On this page