useWallets
Manage wallets connected to the current user, including embedded wallets, external connectors, recovery, and key export.
Usage
import { embeddedWalletId, useWallets } from '@openfort/react';
function WalletSelector() {
const { wallets, activeWallet, setActiveWallet, createWallet, isCreating } = useWallets();
const connectEmbedded = () => setActiveWallet({ walletId: embeddedWalletId, showUI: true });
const connectExternal = (id: string) => setActiveWallet(id);
return (
<div>
<p>Active: {activeWallet?.address}</p>
<button onClick={() => createWallet()} disabled={isCreating}>
Create Wallet
</button>
</div>
);
}Return type
type UseWalletsReturn = {
wallets: UserWallet[]
availableWallets: AvailableWallet[]
activeWallet?: UserWallet
isLoadingWallets: boolean
isCreating: boolean
isConnecting: boolean
isError: boolean
isSuccess: boolean
error?: OpenfortError
reset(): void
setActiveWallet(options: SetActiveWalletOptions | string): Promise<SetActiveWalletResult>
createWallet(options?: CreateWalletOptions): Promise<CreateWalletResult>
setRecovery(options: SetRecoveryOptions): Promise<SetActiveWalletResult>
exportPrivateKey(): Promise<string>
}
type UserWallet = {
address: `0x${string}`
id: string
isAvailable: boolean
isActive?: boolean
recoveryMethod?: 'automatic' | 'password' | 'passkey'
accountType?: 'Smart Account' | 'Externally Owned Account'
ownerAddress?: `0x${string}`
}
type SetActiveWalletResult = {
wallet?: UserWallet
error?: OpenfortError
}Parameters
setActiveWallet
type SetActiveWalletOptions = {
walletId: string | Connector
recovery?: { recoveryMethod: 'automatic' | 'password' | 'passkey'; password?: string }
address?: `0x${string}`
showUI?: boolean
onSuccess?: (data: SetActiveWalletResult) => void
onError?: (error: OpenfortError) => void
}createWallet
type CreateWalletOptions = {
recovery?: { recoveryMethod: 'automatic' | 'password' | 'passkey'; password?: string }
accountType?: 'Smart Account' | 'Externally Owned Account'
onSuccess?: (data: CreateWalletResult) => void
onError?: (error: OpenfortError) => void
}setRecovery
type SetRecoveryOptions = {
previousRecovery: RecoveryParams
newRecovery: RecoveryParams
onSuccess?: (data: SetActiveWalletResult) => void
onError?: (error: OpenfortError) => void
}
type RecoveryParams =
| { recoveryMethod: 'automatic'; encryptionSession: string }
| { recoveryMethod: 'password'; password: string }
| { recoveryMethod: 'passkey'; passkeyInfo?: { passkeyId: string } }