Wallet UI LogoWallet UI

WalletUiAccountContext

The context for the currently selected wallet account.

The WalletUiAccountContext provides information about the currently selected wallet account.

WalletUiAccountState

The context provides an object with the following properties:

NameTypeDescription
accountUiWalletAccountThe currently selected wallet account.
accountKeysstring[]The keys of the account.
clusterSolanaClusterThe currently selected Solana cluster.
setAccount(account: UiWalletAccount) => voidThe React dispatcher to update the selected account.
walletUiWalletThe wallet that the current account belongs to.

Example

This example shows how you could use the context to get the current account.

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

function AccountDetails() {
    const { account } = useContext(WalletUiAccountContext);

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

    return (
        <div>
            <p>Account: {account.address}</p>
        </div>
    );
}