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

useCurrentAccount

The useCurrentAccount hook provides access to the currently selected account.

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

Usage

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

export function MyComponent() {
	const account = useCurrentAccount();

	if (!account) {
		return <div>No account selected</div>;
	}

	return (
		<div>
			<p>Address: {account.address}</p>
			<p>Label: {account.label}</p>
		</div>
	);
}

Return Value

UiWalletAccount | null;

On this page