Skip to content
This new developer portal is under construction. For complete documentation, please refer to the old developer portal.

Client Management

Client management is one of the core capabilities provided by AlgoKit Utils. It allows you to create (auto-retry) algod, indexer and kmd clients against various networks resolved from environment or specified configuration.

Any AlgoKit Utils function that needs one of these clients will take the underlying algosdk classes:

  • algosdk.Algodv2
  • algosdk.Indexer
  • algosdk.Kmd

So inline with the Modularity principle you can use existing logic to get instances of these clients without needing to use the Client management capability if you prefer, including use of libraries like useWallet that have their own configuration mechanism.

Client Manager

The ClientManager is a class that is used to manage client instances.

To get an instance of ClientManager you can get it from either AlgorandClient via algorand.client or instantiate it directly:

import { ClientManager } from '@algorandfoundation/algokit-utils/types/client-manager';
const clientManager = new ClientManager({ algod: algodClient }); // Algod client only
const clientManager = new ClientManager({
algod: algodClient,
indexer: indexerClient,
kmd: kmdClient,
}); // All clients
const clientManager = new ClientManager({ algodConfig }); // Algod config only
const clientManager = new ClientManager({
algodConfig,
indexerConfig,
kmdConfig,
}); // All client configs

Network Configuration

The network configuration is specified using the AlgoClientConfig interface. This same interface is used to specify the config for algod, indexer and kmd SDK clients.

There are a number of ways to produce one of these configuration objects:

Clients

Creating an SDK Client Instance

Once you have the configuration for a client, to get a new client you can use the following functions:

You can also shortcut needing to write the likes of ClientManager.getAlgoClient(ClientManager.getAlgodConfigFromEnvironment()) with environment shortcut methods:

Accessing SDK Clients via ClientManager Instance

Once you have a ClientManager instance, you can access the SDK clients for the various Algorand APIs from it (expressed here as algorand.client to denote the syntax via an AlgorandClient):

const algorand = AlgorandClient.defaultLocalNet();
const algodClient = algorand.client.algod;
const indexerClient = algorand.client.indexer;
const kmdClient = algorand.client.kmd;

If the method to create the ClientManager doesn’t configure indexer or kmd (both of which are optional), then accessing those clients will trigger an error to be thrown:

const algorand = AlgorandClient.fromClients({ algod });
const algodClient = algorand.client.algod; // OK
algorand.client.indexer; // Throws error
algorand.client.kmd; // Throws error

Creating an App Client Instance

See how to create app clients via ClientManager via AlgorandClient.

Creating a TestNet Dispenser API Client Instance

You can also create a TestNet dispenser API client instance from ClientManager too.

Automatic Retry

When receiving an Algod or Indexer client from AlgoKit Utils, it will be a special wrapper client that handles retrying transient failures. This is done via the AlgoHttpClientWithRetry class.

Network Information

To get information about the current network you are connected to, you can use the network() method on ClientManager or the is{Network}() methods (which in turn call network()) as shown below (expressed here as algorand.client to denote the syntax via an AlgorandClient):

const algorand = AlgorandClient.defaultLocalNet();
const { isTestNet, isMainNet, isLocalNet, genesisId, genesisHash } =
await algorand.client.network();
const testNet = await algorand.client.isTestNet();
const mainNet = await algorand.client.isMainNet();
const localNet = await algorand.client.isLocalNet();

The first time network() is called it will make a HTTP call to algod to get the network parameters, but from then on it will be cached within that ClientManager instance for subsequent calls.