Skip to content

WalletUiContext

The WalletUiContext provides all the state and functions for Wallet UI.

The context provides an object with the following properties:

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

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

import { useContext } from 'react';
import { WalletUiContext } from '@wallet-ui/react';
function AccountDetails() {
const { account } = useContext(WalletUiContext);
if (!account) {
return <p>No account selected.</p>;
}
return (
<div>
<p>Account: {account.address}</p>
</div>
);
}