The context.ts file defines the React Context types and providers used throughout the wallet kit for managing wallet state.
Overview
This module exports three main contexts:
- WalletNetworkContext: Manages network selection and available networks
- WalletAccountContext: Manages connected wallet accounts
- WalletUiContext: Manages UI state and wallet interactions
Installation
pnpm dlx shadcn@latest add @wallet-kit/context
Architecture
The three contexts work together to provide complete wallet state management:
API Reference
WalletNetworkContext
Context for managing network state.
Value Type
type WalletNetworkContextValue = {
network: Network;
networks: Network[];
setNetwork(networkId: Network["id"]): void;
}network: The currently active networknetworks: Array of all available networkssetNetwork: Function to change the active network
WalletAccountContext
Context for managing account state.
Value Type
type WalletAccountState = {
account: UiWalletAccount | undefined;
accountKeys: string[];
network: Network;
setAccount: React.Dispatch<React.SetStateAction<UiWalletAccount | undefined>>;
wallet: UiWallet | undefined;
}account: The currently connected account (orundefined)accountKeys: Array of keys used for caching/storagenetwork: The active networksetAccount: Function to set/update the connected accountwallet: The wallet that owns the connected account
WalletUiContext
Context for managing UI state and interactions.
Value Type
type WalletUiContextValue<TClient = unknown> = {
account?: UiWalletAccount;
accountKeys: string[];
client?: TClient;
connect: (wallet: UiWalletAccount) => void;
connected: boolean;
copy: () => void;
disconnect: () => void;
isModalOpen: boolean;
setIsModalOpen: (open: boolean) => void;
wallet?: UiWallet;
wallets: UiWallet[];
}account: The connected accountaccountKeys: Storage keys for the accountclient: Optional blockchain client instanceconnect: Function to connect a wallet accountconnected: Boolean indicating if a wallet is connectedcopy: Function to copy the account addressdisconnect: Function to disconnect the walletisModalOpen: State for wallet connection modalsetIsModalOpen: Function to control modal visibilitywallet: The connected walletwallets: Array of available wallets
Usage
These contexts are typically accessed through hooks:
import { useWalletNetwork } from "@/hooks/use-wallet"
import { useWalletAccount } from "@/hooks/use-wallet"
import { useWallet } from "@/hooks/use-wallet"
export default function MyComponent() {
const { network, setNetwork } = useWalletNetwork()
const { account, wallet } = useWalletAccount()
const { connect, disconnect, connected } = useWallet()
// Use the context values...
}- These contexts are provided by
WalletProvider- you don't need to create them manually - All contexts are typed with TypeScript for type safety
- The contexts work together to provide a complete wallet state management solution
Last updated 11/21/2025