Skip to content

ClientManager

@algorandfoundation/algokit-utils / types/client-manager / ClientManager

types/client-manager.ClientManager

Exposes access to various API clients.

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new ClientManager(clientsOrConfig, algorandClient?): ClientManager

algosdk clients or config for interacting with the official Algorand APIs.

Parameters

NameTypeDescription
clientsOrConfigAlgoConfig | AlgoSdkClientsThe clients or config to use
algorandClient?AlgorandClient-

Returns

ClientManager

Example

const clientManager = new ClientManager({ algod: algodClient });

Example

const clientManager = new ClientManager({
algod: algodClient,
indexer: indexerClient,
kmd: kmdClient,
});

Example

const clientManager = new ClientManager({ algodConfig });

Example

const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig });

Defined in

src/types/client-manager.ts:74

Properties

_algod

Private _algod: AlgodClient

Defined in

src/types/client-manager.ts:49


_algorand

Private Optional _algorand: AlgorandClient

Defined in

src/types/client-manager.ts:52


_getNetworkPromise

Private _getNetworkPromise: undefined | Promise<SuggestedParams>

Defined in

src/types/client-manager.ts:125


_indexer

Private Optional _indexer: IndexerClient

Defined in

src/types/client-manager.ts:50


_kmd

Private Optional _kmd: KmdClient

Defined in

src/types/client-manager.ts:51

Accessors

algod

get algod(): AlgodClient

Returns an algosdk Algod API client.

Returns

AlgodClient

The Algod client

Defined in

src/types/client-manager.ts:93


indexer

get indexer(): IndexerClient

Returns an algosdk Indexer API client or throws an error if it’s not been provided.

Returns

IndexerClient

The Indexer client

Throws

Error if no Indexer client is configured

Defined in

src/types/client-manager.ts:102


indexerIfPresent

get indexerIfPresent(): undefined | IndexerClient

Returns an algosdk Indexer API client or undefined if it’s not been provided.

Returns

undefined | IndexerClient

The Indexer client or undefined

Defined in

src/types/client-manager.ts:111


kmd

get kmd(): KmdClient

Returns an algosdk KMD API client or throws an error if it’s not been provided.

Returns

KmdClient

The KMD client

Throws

Error if no KMD client is configured

Defined in

src/types/client-manager.ts:120

Methods

getAppClientByCreatorAndName

getAppClientByCreatorAndName(params): Promise<AppClient>

Returns a new AppClient client for managing calls and state for an ARC-32/ARC-56 app. This method resolves the app ID by looking up the creator address and name using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).

Parameters

NameTypeDescription
paramsObjectThe parameters to create the app client
params.appLookupCache?AppLookupAn optional cached app lookup that matches a name to on-chain details; either this is needed or indexer is required to be passed in to this ClientManager on construction.
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name
params.appSpecstring | Arc56Contract | AppSpecThe ARC-56 or ARC-32 application spec as either: _ Parsed JSON ARC-56 Contract _ Parsed JSON ARC-32 AppSpec * Raw JSON string (in either ARC-56 or ARC-32 format)
params.approvalSourceMap?ProgramSourceMapOptional source map for the approval program
params.clearSourceMap?ProgramSourceMapOptional source map for the clear state program
params.creatorAddressstring | AddressThe address of the creator account for the app
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).
params.ignoreCache?booleanWhether or not to ignore the AppDeployer lookup cache and force an on-chain lookup, default: use any cached value

Returns

Promise<AppClient>

The AppClient instance

Example

const appClient = clientManager.getAppClientByCreatorAndName({
appSpec: '{/* ARC-56 or ARC-32 compatible JSON *}',
// appId resolved by looking for app ID of named app by this creator
creatorAddress: 'CREATORADDRESS',
});

Defined in

src/types/client-manager.ts:284


getAppClientById

getAppClientById(params): AppClient

Returns a new AppClient client for managing calls and state for an ARC-32/ARC-56 app.

Parameters

NameTypeDescription
paramsObjectThe parameters to create the app client
params.appIdbigintThe ID of the app instance this client should make calls against.
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name
params.appSpecstring | Arc56Contract | AppSpecThe ARC-56 or ARC-32 application spec as either: _ Parsed JSON ARC-56 Contract _ Parsed JSON ARC-32 AppSpec * Raw JSON string (in either ARC-56 or ARC-32 format)
params.approvalSourceMap?ProgramSourceMapOptional source map for the approval program
params.clearSourceMap?ProgramSourceMapOptional source map for the clear state program
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

Returns

AppClient

The AppClient instance

Example

const appClient = clientManager.getAppClientById({
appSpec: '{/* ARC-56 or ARC-32 compatible JSON *}',
appId: 12345n,
});

Defined in

src/types/client-manager.ts:307


getAppClientByNetwork

getAppClientByNetwork(params): Promise<AppClient>

Returns a new AppClient client for managing calls and state for an ARC-56 app. This method resolves the app ID for the current network based on pre-determined network-specific app IDs specified in the ARC-56 app spec.

If no IDs are in the app spec or the network isn’t recognised, an error is thrown.

Parameters

NameTypeDescription
paramsObjectThe parameters to create the app client
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name
params.appSpecstring | Arc56Contract | AppSpecThe ARC-56 or ARC-32 application spec as either: _ Parsed JSON ARC-56 Contract _ Parsed JSON ARC-32 AppSpec * Raw JSON string (in either ARC-56 or ARC-32 format)
params.approvalSourceMap?ProgramSourceMapOptional source map for the approval program
params.clearSourceMap?ProgramSourceMapOptional source map for the clear state program
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

Returns

Promise<AppClient>

The AppClient instance

Example

const appClient = clientManager.getAppClientByNetwork({
appSpec: '{/* ARC-56 or ARC-32 compatible JSON *}',
// appId resolved by using ARC-56 spec to find app ID for current network
});

Defined in

src/types/client-manager.ts:330


getAppFactory

getAppFactory(params): AppFactory

Returns a new AppFactory client

Parameters

NameTypeDescription
paramsObjectThe parameters to create the app factory
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name.
params.appSpecstring | Arc56Contract | AppSpecThe ARC-56 or ARC-32 application spec as either: _ Parsed JSON ARC-56 Contract _ Parsed JSON ARC-32 AppSpec * Raw JSON string (in either ARC-56 or ARC-32 format)
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).
params.deletable?booleanWhether or not the contract should have deploy-time permanence control set, undefined = ignore. If specified here will get used in calls to deploy and create calls unless overridden in those calls. Useful if you want to vend multiple contracts from the same factory without specifying this value for each call.
params.deployTimeParams?TealTemplateParamsOptional deploy-time TEAL template replacement parameters. If specified here will get used in calls to deploy and create calls unless overridden in those calls. Useful if you want to vend multiple contracts from the same factory without specifying this value for each call.
params.updatable?booleanWhether or not the contract should have deploy-time immutability control set, undefined = ignore. If specified here will get used in calls to deploy and create calls unless overridden in those calls. Useful if you want to vend multiple contracts from the same factory without specifying this value for each call.
params.version?stringThe version of app that is / will be deployed; defaults to 1.0

Returns

AppFactory

The AppFactory instance

Example

const factory = clientManager.getAppFactory({
appSpec: '{/* ARC-56 or ARC-32 compatible JSON */}',
});

Example

const factory = clientManager.getAppFactory({
appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,
defaultSender: 'SENDERADDRESS',
appName: 'OverriddenAppName',
version: '2.0.0',
updatable: true,
deletable: false,
deployTimeParams: { ONE: 1, TWO: 'value' },
});

Defined in

src/types/client-manager.ts:261


getTestNetDispenser

getTestNetDispenser(params): TestNetDispenserApiClient

Returns a TestNet Dispenser API client.

Refer to docs on guidance to obtain an access token.

Parameters

NameTypeDescription
paramsTestNetDispenserApiClientParamsAn object containing parameters for the TestNetDispenserApiClient class.

Returns

TestNetDispenserApiClient

An instance of the TestNetDispenserApiClient class.

Example

const client = clientManager.getTestNetDispenser({
authToken: 'your_auth_token',
requestTimeout: 15,
});

Defined in

src/types/client-manager.ts:215


getTestNetDispenserFromEnvironment

getTestNetDispenserFromEnvironment(params?): TestNetDispenserApiClient

Returns a TestNet Dispenser API client, loading the auth token from process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN.

Refer to docs on guidance to obtain an access token.

Parameters

NameTypeDescription
params?Omit<TestNetDispenserApiClientParams, "authToken">An object containing parameters for the TestNetDispenserApiClient class.

Returns

TestNetDispenserApiClient

An instance of the TestNetDispenserApiClient class.

Example

const client = clientManager.getTestNetDispenserFromEnvironment({
requestTimeout: 15,
});

Defined in

src/types/client-manager.ts:234


getTypedAppClientByCreatorAndName

getTypedAppClientByCreatorAndName<TClient>(typedClient, params): Promise<InstanceType<TClient>>

Returns a new typed client, resolving the app by creator address and name.

Type parameters

NameType
TClientextends TypedAppClient<InstanceType<TClient>>

Parameters

NameTypeDescription
typedClientTClientThe typed client type to use
paramsObjectThe params to resolve the app by creator address and name
params.appLookupCache?AppLookupAn optional cached app lookup that matches a name to on-chain details; either this is needed or indexer is required to be passed in to this ClientManager on construction.
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name
params.approvalSourceMap?ProgramSourceMapOptional source map for the approval program
params.clearSourceMap?ProgramSourceMapOptional source map for the clear state program
params.creatorAddressstring | AddressThe address of the creator account for the app
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).
params.ignoreCache?booleanWhether or not to ignore the AppDeployer lookup cache and force an on-chain lookup, default: use any cached value

Returns

Promise<InstanceType<TClient>>

The typed client instance

Example

const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {
creatorAddress: 'CREATORADDRESS',
defaultSender: alice,
});

Example

const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {
creatorAddress: 'CREATORADDRESS',
name: 'contract-name',
defaultSender: alice,
});

Defined in

src/types/client-manager.ts:358


getTypedAppClientById

getTypedAppClientById<TClient>(typedClient, params): InstanceType<TClient>

Returns a new typed client, resolving the app by app ID.

Type parameters

NameType
TClientextends TypedAppClient<InstanceType<TClient>>

Parameters

NameTypeDescription
typedClientTClientThe typed client type to use
paramsObjectThe params to resolve the app by ID
params.appIdbigintThe ID of the app instance this client should make calls against.
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name
params.approvalSourceMap?ProgramSourceMapOptional source map for the approval program
params.clearSourceMap?ProgramSourceMapOptional source map for the clear state program
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

Returns

InstanceType<TClient>

The typed client instance

Example

const appClient = clientManager.getTypedAppClientById(MyContractClient, {
appId: 12345n,
defaultSender: alice,
});

Defined in

src/types/client-manager.ts:382


getTypedAppClientByNetwork

getTypedAppClientByNetwork<TClient>(typedClient, params?): Promise<InstanceType<TClient>>

Returns a new typed client, resolves the app ID for the current network based on pre-determined network-specific app IDs specified in the ARC-56 app spec.

If no IDs are in the app spec or the network isn’t recognised, an error is thrown.

Type parameters

NameType
TClientextends TypedAppClient<InstanceType<TClient>>

Parameters

NameTypeDescription
typedClientTClientThe typed client type to use
params?ObjectThe params to resolve the app by network
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name
params.approvalSourceMap?ProgramSourceMapOptional source map for the approval program
params.clearSourceMap?ProgramSourceMapOptional source map for the clear state program
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

Returns

Promise<InstanceType<TClient>>

The typed client instance

Example

const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {
defaultSender: alice,
});

Defined in

src/types/client-manager.ts:408


getTypedAppFactory

getTypedAppFactory<TClient>(typedFactory, params?): TClient

Returns a new typed app factory.

Type parameters

Name
TClient

Parameters

NameTypeDescription
typedFactoryTypedAppFactory<TClient>The typed factory type to use
params?ObjectThe params to resolve the factory by
params.appName?stringOptional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name.
params.defaultSender?string | AddressOptional address to use for the account to use as the default sender for calls.
params.defaultSigner?TransactionSignerOptional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).
params.deletable?booleanWhether or not the contract should have deploy-time permanence control set, undefined = ignore. If specified here will get used in calls to deploy and create calls unless overridden in those calls. Useful if you want to vend multiple contracts from the same factory without specifying this value for each call.
params.deployTimeParams?TealTemplateParamsOptional deploy-time TEAL template replacement parameters. If specified here will get used in calls to deploy and create calls unless overridden in those calls. Useful if you want to vend multiple contracts from the same factory without specifying this value for each call.
params.updatable?booleanWhether or not the contract should have deploy-time immutability control set, undefined = ignore. If specified here will get used in calls to deploy and create calls unless overridden in those calls. Useful if you want to vend multiple contracts from the same factory without specifying this value for each call.
params.version?stringThe version of app that is / will be deployed; defaults to 1.0

Returns

TClient

The typed client instance

Example

const appFactory = clientManager.getTypedAppFactory(MyContractClient, {
sender: alice,
});

Defined in

src/types/client-manager.ts:431


isLocalNet

isLocalNet(): Promise<boolean>

Returns true if the current network is LocalNet.

Returns

Promise<boolean>

True if the current network is LocalNet.

Example

const isLocalNet = await clientManager.isLocalNet();

Defined in

src/types/client-manager.ts:171


isMainNet

isMainNet(): Promise<boolean>

Returns true if the current network is MainNet.

Returns

Promise<boolean>

True if the current network is MainNet.

Example

const isMainNet = await clientManager.isMainNet();

Defined in

src/types/client-manager.ts:195


isTestNet

isTestNet(): Promise<boolean>

Returns true if the current network is TestNet.

Returns

Promise<boolean>

True if the current network is TestNet.

Example

const isTestNet = await clientManager.isTestNet();

Defined in

src/types/client-manager.ts:183


network

network(): Promise<NetworkDetails>

Get details about the current network.

Returns

Promise<NetworkDetails>

The current network details

Example

const network = await networkClient.network();
const genesisId = network.genesisId;

Defined in

src/types/client-manager.ts:135


genesisIdIsLocalNet

genesisIdIsLocalNet(genesisId): boolean

Returns true if the given network genesisId is associated with a LocalNet network.

Parameters

NameTypeDescription
genesisIdstringThe network genesis ID

Returns

boolean

Whether the given genesis ID is associated with a LocalNet network

Example

const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0');

Defined in

src/types/client-manager.ts:159


getAlgoNodeConfig

getAlgoNodeConfig(network, config): AlgoClientConfig

Returns the Algorand configuration to point to the free tier of the AlgoNode service.

Parameters

NameTypeDescription
network"testnet" | "mainnet"Which network to connect to - TestNet or MainNet
config"algod" | "indexer"Which algod config to return - Algod or Indexer

Returns

AlgoClientConfig

The AlgoNode client configuration

Example

const config = ClientManager.getAlgoNodeConfig('testnet', 'algod');

Defined in

src/types/client-manager.ts:545


getAlgodClient

getAlgodClient(config): AlgodClient

Returns an algod SDK client that automatically retries on idempotent calls.

Parameters

NameTypeDescription
configAlgoClientConfigThe config of the client

Returns

AlgodClient

The Algod client

Example

const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'));
await algod.healthCheck().do();

Example

const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'));
await algod.healthCheck().do();

Example

const algod = ClientManager.getAlgodClient({
server: 'http://localhost',
port: '4001',
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
});
await algod.healthCheck().do();

Defined in

src/types/client-manager.ts:590


getAlgodClientFromEnvironment

getAlgodClientFromEnvironment(): AlgodClient

Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).

Returns

AlgodClient

The Algod client

Example

// Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
const algod = ClientManager.getAlgodClientFromEnvironment();
await algod.healthCheck().do();

Defined in

src/types/client-manager.ts:608


getAlgodConfigFromEnvironment

getAlgodConfigFromEnvironment(): AlgoClientConfig

Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)

Expects process.env.ALGOD_SERVER to be defined, and you can also specify process.env.ALGOD_PORT and process.env.ALGOD_TOKEN.

Returns

AlgoClientConfig

The Algod client configuration

Throws

Error if process.env.ALGOD_SERVER is not defined

Example

const config = ClientManager.getAlgodConfigFromEnvironment();

Defined in

src/types/client-manager.ts:492


getConfigFromEnvironmentOrLocalNet

getConfigFromEnvironmentOrLocalNet(): AlgoConfig

Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)

If both process.env.INDEXER_SERVER and process.env.ALGOD_SERVER is defined it will use both along with optional process.env.ALGOD_PORT, process.env.ALGOD_TOKEN, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN.

If only process.env.ALGOD_SERVER is defined it will use this along with optional process.env.ALGOD_PORT and process.env.ALGOD_TOKEN and leave indexer as undefined.

If only process.env.INDEXER_SERVER is defined it will use the default (LocalNet) configuration for both algod and indexer.

It will return a KMD configuration that uses process.env.KMD_PORT (or port 4002) if process.env.ALGOD_SERVER is defined, otherwise it will use the default LocalNet config unless it detects testnet or mainnet.

Returns

AlgoConfig

The config for algod, indexer and kmd

Example

const config = ClientManager.getConfigFromEnvironmentOrLocalNet();

Defined in

src/types/client-manager.ts:456


getDefaultLocalNetConfig

getDefaultLocalNetConfig(configOrPort): AlgoClientConfig

Returns the Algorand configuration to point to the default LocalNet.

Parameters

NameTypeDescription
configOrPortnumber | "algod" | "indexer" | "kmd"Which algod config to return - algod, kmd, or indexer OR a port number

Returns

AlgoClientConfig

The LocalNet client configuration

Example

const config = ClientManager.getDefaultLocalNetConfig('algod');

Defined in

src/types/client-manager.ts:561


getIndexerClient

getIndexerClient(config): IndexerClient

Returns an indexer SDK client that automatically retries on idempotent calls

Parameters

NameTypeDescription
configAlgoClientConfigThe config of the client

Returns

IndexerClient

The Indexer client

Example

const indexer = ClientManager.getIndexerClient(
ClientManager.getAlgoNodeConfig('testnet', 'indexer'),
);
await indexer.makeHealthCheck().do();

Example

const indexer = ClientManager.getIndexerClient(
ClientManager.getAlgoNodeConfig('mainnet', 'indexer'),
);
await indexer.makeHealthCheck().do();

Example

const indexer = ClientManager.getIndexerClient({
server: 'http://localhost',
port: '8980',
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
});
await indexer.makeHealthCheck().do();

Defined in

src/types/client-manager.ts:633


getIndexerClientFromEnvironment

getIndexerClientFromEnvironment(): IndexerClient

Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).

Returns

IndexerClient

The Indexer client

Example

// Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
const indexer = ClientManager.getIndexerClientFromEnvironment();
await indexer.makeHealthCheck().do();

Defined in

src/types/client-manager.ts:652


getIndexerConfigFromEnvironment

getIndexerConfigFromEnvironment(): AlgoClientConfig

Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).

Expects process.env.INDEXER_SERVER to be defined, and you can also specify process.env.INDEXER_PORT and process.env.INDEXER_TOKEN.

Returns

AlgoClientConfig

The Indexer client configuration

Throws

Error if process.env.INDEXER_SERVER is not defined

Example

const config = ClientManager.getIndexerConfigFromEnvironment();

Defined in

src/types/client-manager.ts:519


getKmdClient

getKmdClient(config): KmdClient

Returns a KMD SDK client.

KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.

Parameters

NameTypeDescription
configAlgoClientConfigThe config for the client

Returns

KmdClient

The KMD client

Example

const kmd = ClientManager.getKmdClient({
server: 'http://localhost',
port: '4002',
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
});

Defined in

src/types/client-manager.ts:668


getKmdClientFromEnvironment

getKmdClientFromEnvironment(): KmdClient

Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).

Returns

KmdClient

The KMD client

Example

// Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
const kmd = ClientManager.getKmdClientFromEnvironment();

Defined in

src/types/client-manager.ts:683