Configuration

The WalletManager class is the core of use-wallet, responsible for managing wallet connections and network configurations. This guide covers how to configure the WalletManager for your application.

Basic Configuration

The WalletManager constructor accepts a configuration object with the following structure:

interface WalletManagerConfig {
  wallets?: SupportedWallet[]      // Array of wallets to enable
  networks?: Record<string, NetworkConfig>  // Custom network configurations
  defaultNetwork?: string          // Network to use by default
  options?: WalletManagerOptions   // Additional options
}

Here's a basic example:

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

const manager = new WalletManager({
  wallets: [WalletId.PERA, WalletId.DEFLY],
  defaultNetwork: NetworkId.MAINNET // or just 'mainnet'
})

Configuring Wallets

The wallets array determines which wallets will be available in your application. For each wallet, you can provide either:

  • Just the wallet identifier (for wallets with no required options)

  • A configuration object specifying required options and optional customizations

Some wallets require specific options to be provided. TypeScript will show errors if these required options are omitted or if you try to use just the identifier.

Here's an example showing common wallet configurations, including popular production wallets and those that require specific options:

See the Supported Wallets page for details about all wallets available in the library, including those used for development and testing.

Network Configuration

By default, use-wallet comes with configurations for:

  • MainNet

  • TestNet

  • BetaNet

  • LocalNet (for development)

For all public Algorand networks (MainNet, TestNet, BetaNet), the default configurations use Nodely's free public APIarrow-up-right, so you don't need to configure network settings to get started.

circle-info

Nodelyarrow-up-right provides their public API free of charge with certain usage requirementsarrow-up-right. For production applications with significant traffic, consider either:

If you need to use a different node or connect to other AVM-compatible networks, you can customize the network configuration in one of two ways:

Direct Network Configuration

For applications using a single network, you can provide the configuration directly:

This approach is particularly useful when the network configuration comes from environment variables.

Using NetworkConfigBuilder

For applications that support multiple networks with custom configurations, the NetworkConfigBuilder class provides a convenient, fluent interface:

Custom Networks

To add configurations for other AVM-compatible networks, use the addNetwork method:

When adding a custom network, in addition to setting the Algod configuration (token, baseServer, port), you should also set the optional properties that are used by the specific wallet providers you want to support.

Network Configuration Details

Each network configuration consists of required Algod client settings and optional network identifiers. For the public Algorand networks (MainNet, TestNet, BetaNet), use-wallet provides default configurations with all necessary properties pre-configured.

Most users will only need to customize the Algod client settings:

Algod Configuration

The token property can be provided in several formats:

Most applications will use either a string token or an AlgodTokenHeader.

The remaining Algod client settings include:

  • baseServer: The URL of the Algod node you want to connect to.

  • port: The port number the Algod node is listening on. Common values include '443' for HTTPS connections and '4001' for local development. Some hosting providers may use different ports.

  • headers: Optional additional HTTP headers to include with requests.

circle-info

Note: Starting with v4.0.0, use-wallet supports user-customizable node settings at runtime. If your application implements the necessary UI components, users can override the configured Algod settings to connect to a different node.

See the Runtime Node Configuration guide for details.

Optional Properties

The optional network properties are only needed when defining custom networks. They serve specific purposes for different wallet providers:

For example, when adding a custom network:

If any of these optional properties are missing when required by a wallet, use-wallet will attempt to fetch them from the node (for genesisHash and genesisId) or use sensible defaults (setting isTestnet to false).

However, providing them in your configuration can save network requests and ensure proper wallet functionality.

Manager Options

The optional options object allows you to configure the WalletManager's behavior:

Complete Example

Here's a complete configuration example combining all the elements:

Next Steps

The configuration options described in this guide apply to all framework adapters. However, each framework has its own specific setup steps for integrating the configured WalletManager into your application. See the framework-specific guides for detailed setup instructions:

Last updated