Runtime Node Configuration

Starting with v4.0.0, use-wallet provides methods to update Algod node configurations at runtime. This feature gives users the freedom to connect to their preferred nodes while maintaining your application's default configuration as a fallback option.

Common use cases include:

  • Users running their own private Algod nodes

  • Teams working with custom network configurations

  • Connecting to fallback nodes (like Nodely's backup endpoints) when the primary node is unavailable

Basic Usage

The useNetwork hook/composable provides two methods for managing node configurations:

  • updateAlgodConfig - Update a network's node configuration

  • resetNetworkConfig - Reset a network's configuration to defaults

import { useNetwork } from '@txnlab/use-wallet-react'

function NodeConfig() {
  const { updateAlgodConfig, resetNetworkConfig } = useNetwork()

  const handleNodeChange = () => {
    // Update node configuration for MainNet
    updateAlgodConfig('mainnet', {
      baseServer: 'https://secondary-node.com',
      port: '443',
      token: ''
    })
  }

  const handleReset = () => {
    // Reset MainNet back to default configuration
    resetNetworkConfig('mainnet')
  }

  return (
    <div>
      <button onClick={handleNodeChange}>
        Use Secondary Node
      </button>
      <button onClick={handleReset}>
        Reset Node
      </button>
    </div>
  )
}

Configuration Persistence

Node configurations are automatically saved to local storage. This means:

  • Custom configurations persist across page reloads

  • Each network's configuration can be customized independently

  • Resetting a network only affects that specific network's configuration

Configuration Options

When updating node configurations, you can provide any of these settings:

Automatic Updates

When updating the configuration for the active network, use-wallet automatically:

  1. Creates a new Algod client with the updated configuration

  2. Updates all components that depend on the Algod client

  3. Saves the configuration to local storage

No additional steps are needed to start using the new node.

Example Form

Here's a complete example showing how to implement a node configuration form:

Last updated