Wallet UI LogoWallet UI

useWalletUi

The primary hook for interacting with wallet state.

The useWalletUi hook is the primary hook for interacting with the wallet state. It provides access to the connected wallet, account, cluster information, and functions to connect, disconnect, and copy the address.

Return Value

The hook returns an object with the following properties:

NameTypeDescription
accountUiWalletAccountThe currently selected wallet account.
walletUiWalletThe wallet that the current account belongs to.
connectedbooleanA boolean indicating if a wallet is connected.
walletsUiWallet[]An array of all detected wallets.
clusterSolanaClusterThe currently selected Solana cluster.
connect(account: UiWalletAccount) => voidA function to set the active wallet account.
disconnect() => voidA function to disconnect the current wallet.
copy() => voidA function to copy the current account address to the clipboard.

Example

import { useWalletUi } from '@wallet-ui/react';

function WalletStatus() {
    const { connected, account, disconnect } = useWalletUi();

    if (!connected) {
        return <p>Not connected</p>;
    }

    return (
        <div>
            <p>Connected to {account?.address}</p>
            <button onClick={disconnect}>Disconnect</button>
        </div>
    );
}