Skip to main content
use-wallet provides types and utilities for configuring connections to Algorand networks. You can use the default network configurations or customize them to connect to your own nodes.

NetworkConfig

interface NetworkConfig {
  algod: AlgodConfig
  genesisHash?: string
  genesisId?: string
  isTestnet?: boolean
  caipChainId?: string
}
Defines the configuration for an Algorand network.
algod
AlgodConfig
required
Configuration for connecting to an Algod node
genesisHash
string
The genesis hash of the network
genesisId
string
The genesis ID of the network (e.g., ‘mainnet-v1.0’, ‘testnet-v1.0’)
isTestnet
boolean
Whether this is a test network
caipChainId
string
The CAIP-2 chain identifier for this network

AlgodConfig

interface AlgodConfig {
  token: string | algosdk.AlgodTokenHeader | algosdk.CustomTokenHeader | algosdk.BaseHTTPClient
  baseServer: string
  port?: string | number
  headers?: Record<string, string>
}
Configuration for connecting to an Algod node.
token
string | AlgodTokenHeader | CustomTokenHeader | BaseHTTPClient
required
API token for authentication, or a custom HTTP client. Can be an empty string for public nodes
baseServer
string
required
Base URL of the Algod server (e.g., ‘https://mainnet-api.4160.nodely.dev’)
port
string | number
Port number for the Algod server (optional for HTTPS URLs)
headers
Record<string, string>
Additional HTTP headers to include in requests

Default Network Configurations

use-wallet includes default configurations for common Algorand networks:
import { DEFAULT_NETWORK_CONFIG } from '@txnlab/use-wallet'

// Available networks:
// - mainnet
// - testnet
// - betanet
// - fnet
// - localnet

Mainnet

{
  algod: {
    token: '',
    baseServer: 'https://mainnet-api.4160.nodely.dev',
    headers: {}
  },
  isTestnet: false,
  genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
  genesisId: 'mainnet-v1.0',
  caipChainId: 'algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k'
}

Testnet

{
  algod: {
    token: '',
    baseServer: 'https://testnet-api.4160.nodely.dev',
    headers: {}
  },
  isTestnet: true,
  genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=',
  genesisId: 'testnet-v1.0',
  caipChainId: 'algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe'
}

Localnet

{
  algod: {
    token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    baseServer: 'http://localhost',
    port: 4001,
    headers: {}
  },
  isTestnet: true
}

NetworkConfigBuilder

The NetworkConfigBuilder class provides a fluent API for customizing network configurations.
class NetworkConfigBuilder {
  mainnet(config: DefaultNetworkConfig): NetworkConfigBuilder
  testnet(config: DefaultNetworkConfig): NetworkConfigBuilder
  betanet(config: DefaultNetworkConfig): NetworkConfigBuilder
  fnet(config: DefaultNetworkConfig): NetworkConfigBuilder
  localnet(config: Partial<NetworkConfig>): NetworkConfigBuilder
  addNetwork(id: string, config: NetworkConfig): NetworkConfigBuilder
  build(): Record<string, NetworkConfig>
}

Example: Custom network configuration

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

const networks = new NetworkConfigBuilder()
  .mainnet({
    algod: {
      token: 'your-api-token',
      baseServer: 'https://your-mainnet-node.com',
      port: 443,
      headers: { 'X-API-Key': 'your-key' }
    }
  })
  .testnet({
    algod: {
      token: '',
      baseServer: 'https://your-testnet-node.com'
    }
  })
  .addNetwork('custom', {
    algod: {
      token: 'token',
      baseServer: 'https://custom-node.com'
    },
    isTestnet: true
  })
  .build()

const walletManager = new WalletManager({
  wallets: [WalletId.PERA],
  networks,
  defaultNetwork: 'mainnet'
})

Builder methods

mainnet
(config: DefaultNetworkConfig) => NetworkConfigBuilder
Customize the mainnet configuration. Genesis hash and ID cannot be overridden
testnet
(config: DefaultNetworkConfig) => NetworkConfigBuilder
Customize the testnet configuration. Genesis hash and ID cannot be overridden
betanet
(config: DefaultNetworkConfig) => NetworkConfigBuilder
Customize the betanet configuration. Genesis hash and ID cannot be overridden
fnet
(config: DefaultNetworkConfig) => NetworkConfigBuilder
Customize the fnet configuration. Genesis hash and ID cannot be overridden
localnet
(config: Partial<NetworkConfig>) => NetworkConfigBuilder
Customize the localnet configuration. All properties can be overridden
addNetwork
(id: string, config: NetworkConfig) => NetworkConfigBuilder
Add a custom network with a unique ID. Cannot use reserved IDs (mainnet, testnet, betanet, fnet, localnet)
build
() => Record<string, NetworkConfig>
Build and return the final network configuration object

NetworkId

enum NetworkId {
  MAINNET = 'mainnet',
  TESTNET = 'testnet',
  BETANET = 'betanet',
  FNET = 'fnet',
  LOCALNET = 'localnet'
}
Enum of standard network identifiers.

Runtime network configuration

You can also update network configurations at runtime using WalletManager methods:
// Update Algod configuration for a network
walletManager.updateAlgodConfig('mainnet', {
  token: 'new-token',
  baseServer: 'https://new-node.com'
})

// Reset to original configuration
walletManager.resetNetworkConfig('mainnet')

// Switch active network
await walletManager.setActiveNetwork('mainnet')
See the WalletManager API reference for more details.

Build docs developers (and LLMs) love