Skip to main content
WalletManager is the entry point for integrating use-wallet into your application. It manages wallet instances, network configuration, state persistence, and provides access to connected wallets and signing methods.

Constructor

new WalletManager(config?: WalletManagerConfig)
config
WalletManagerConfig
Configuration object for the wallet manager

Example

import { WalletManager, WalletId } from '@txnlab/use-wallet'

const walletManager = new WalletManager({
  wallets: [
    WalletId.PERA,
    WalletId.DEFLY,
    {
      id: WalletId.WALLETCONNECT,
      options: { projectId: 'your-project-id' }
    }
  ],
  defaultNetwork: 'testnet'
})

// Resume sessions for previously connected wallets
await walletManager.resumeSessions()

Properties

wallets

get wallets(): BaseWallet[]
Returns an array of all initialized wallet instances.

activeWallet

get activeWallet(): BaseWallet | null
Returns the currently active wallet instance, or null if no wallet is active.

activeWalletAccounts

get activeWalletAccounts(): WalletAccount[] | null
Returns the accounts of the active wallet, or null if no wallet is active.

activeWalletAddresses

get activeWalletAddresses(): string[] | null
Returns the addresses of the active wallet’s accounts, or null if no wallet is active.

activeAccount

get activeAccount(): WalletAccount | null
Returns the active account of the active wallet, or null if no wallet is active.

activeAddress

get activeAddress(): string | null
Returns the address of the active account, or null if no wallet is active.

algodClient

get algodClient(): algosdk.Algodv2
set algodClient(client: algosdk.Algodv2)
The Algod client for the currently active network. Can be read or set.

activeNetwork

get activeNetwork(): string
Returns the ID of the currently active network (e.g., ‘mainnet’, ‘testnet’).

networkConfig

get networkConfig(): Record<string, NetworkConfig>
Returns all network configurations.

activeNetworkConfig

get activeNetworkConfig(): NetworkConfig
Returns the configuration for the currently active network.

status

get status(): ManagerStatus
Returns the current status: 'initializing' or 'ready'.

isReady

get isReady(): boolean
Returns true if the manager status is 'ready'.

signTransactions

get signTransactions(): BaseWallet['signTransactions']
Returns the signTransactions method of the active wallet. Throws an error if no wallet is active.

transactionSigner

get transactionSigner(): algosdk.TransactionSigner
Returns an algosdk.TransactionSigner function from the active wallet. Throws an error if no wallet is active.

Methods

resumeSessions

async resumeSessions(): Promise<void>
Attempts to resume sessions for all previously connected wallets. Should be called after instantiation to restore wallet connections.
const walletManager = new WalletManager({ wallets: [WalletId.PERA] })
await walletManager.resumeSessions()

disconnect

async disconnect(): Promise<void>
Disconnects all connected wallets.
await walletManager.disconnect()

getWallet

getWallet(walletKey: WalletKey): BaseWallet | undefined
walletKey
WalletKey
required
The wallet key (typically the wallet ID, or composite key for skinned WalletConnect instances)
Returns the wallet instance for the given wallet key, or undefined if not found.
const peraWallet = walletManager.getWallet(WalletId.PERA)
if (peraWallet) {
  await peraWallet.connect()
}

setActiveNetwork

async setActiveNetwork(networkId: NetworkId | string): Promise<void>
networkId
NetworkId | string
required
The ID of the network to switch to
Switches the active network and updates the Algod client.
await walletManager.setActiveNetwork('mainnet')

updateAlgodConfig

updateAlgodConfig(networkId: string, algodConfig: Partial<AlgodConfig>): void
networkId
string
required
The ID of the network to update
algodConfig
Partial<AlgodConfig>
required
The Algod configuration properties to update
Updates the Algod configuration for a specific network. If the network is currently active, the Algod client is recreated with the new configuration.
walletManager.updateAlgodConfig('mainnet', {
  baseServer: 'https://my-custom-node.com',
  token: 'my-token'
})

resetNetworkConfig

resetNetworkConfig(networkId: string): void
networkId
string
required
The ID of the network to reset
Resets the network configuration to its base (initial) configuration, removing any customizations.
walletManager.resetNetworkConfig('mainnet')

subscribe

subscribe(callback: (state: State) => void): () => void
callback
(state: State) => void
required
Function to call when state changes
Subscribes to state changes. Returns an unsubscribe function.
const unsubscribe = walletManager.subscribe((state) => {
  console.log('Active wallet:', state.activeWallet)
  console.log('Active network:', state.activeNetwork)
})

// Later, to unsubscribe
unsubscribe()

State Persistence

WalletManager automatically persists wallet connection state to localStorage under the key @txnlab/use-wallet:v4. This includes:
  • Connected wallets and their accounts
  • Active wallet selection
  • Active network selection
  • Custom network configurations
State is automatically restored when creating a new WalletManager instance.

Build docs developers (and LLMs) love