Skip to content

ClientManager

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

types/client-manager.ClientManager

Exposes access to various API clients.

new ClientManager(clientsOrConfig, algorandClient?): ClientManager

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

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

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 });

src/types/client-manager.ts:74

Private _algod: AlgodClient

src/types/client-manager.ts:49


Private Optional _algorand: AlgorandClient

src/types/client-manager.ts:52


Private _getNetworkPromise: undefined | Promise<SuggestedParams>

src/types/client-manager.ts:125


Private Optional _indexer: IndexerClient

src/types/client-manager.ts:50


Private Optional _kmd: KmdClient

src/types/client-manager.ts:51

get algod(): AlgodClient

Returns an algosdk Algod API client.

AlgodClient

The Algod client

src/types/client-manager.ts:93


get indexer(): IndexerClient

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

IndexerClient

The Indexer client

Throws

Error if no Indexer client is configured

src/types/client-manager.ts:102


get indexerIfPresent(): undefined | IndexerClient

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

undefined | IndexerClient

The Indexer client or undefined

src/types/client-manager.ts:111


get kmd(): KmdClient

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

KmdClient

The KMD client

Throws

Error if no KMD client is configured

src/types/client-manager.ts:120

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).

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

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',
});

src/types/client-manager.ts:284


getAppClientById(params): AppClient

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

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).

AppClient

The AppClient instance

Example

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

src/types/client-manager.ts:307


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.

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).

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
});

src/types/client-manager.ts:330


getAppFactory(params): AppFactory

Returns a new AppFactory client

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

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' },
});

src/types/client-manager.ts:261


getTestNetDispenser(params): TestNetDispenserApiClient

Returns a TestNet Dispenser API client.

Refer to docs on guidance to obtain an access token.

NameTypeDescription
paramsTestNetDispenserApiClientParamsAn object containing parameters for the TestNetDispenserApiClient class.

TestNetDispenserApiClient

An instance of the TestNetDispenserApiClient class.

Example

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

src/types/client-manager.ts:215


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.

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

TestNetDispenserApiClient

An instance of the TestNetDispenserApiClient class.

Example

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

src/types/client-manager.ts:234


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

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

NameType
TClientextends TypedAppClient<InstanceType<TClient>>
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

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,
});

src/types/client-manager.ts:358


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

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

NameType
TClientextends TypedAppClient<InstanceType<TClient>>
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).

InstanceType<TClient>

The typed client instance

Example

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

src/types/client-manager.ts:382


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.

NameType
TClientextends TypedAppClient<InstanceType<TClient>>
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).

Promise<InstanceType<TClient>>

The typed client instance

Example

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

src/types/client-manager.ts:408


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

Returns a new typed app factory.

Name
TClient
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

TClient

The typed client instance

Example

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

src/types/client-manager.ts:431


isLocalNet(): Promise<boolean>

Returns true if the current network is LocalNet.

Promise<boolean>

True if the current network is LocalNet.

Example

const isLocalNet = await clientManager.isLocalNet();

src/types/client-manager.ts:171


isMainNet(): Promise<boolean>

Returns true if the current network is MainNet.

Promise<boolean>

True if the current network is MainNet.

Example

const isMainNet = await clientManager.isMainNet();

src/types/client-manager.ts:195


isTestNet(): Promise<boolean>

Returns true if the current network is TestNet.

Promise<boolean>

True if the current network is TestNet.

Example

const isTestNet = await clientManager.isTestNet();

src/types/client-manager.ts:183


network(): Promise<NetworkDetails>

Get details about the current network.

Promise<NetworkDetails>

The current network details

Example

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

src/types/client-manager.ts:135


genesisIdIsLocalNet(genesisId): boolean

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

NameTypeDescription
genesisIdstringThe network genesis ID

boolean

Whether the given genesis ID is associated with a LocalNet network

Example

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

src/types/client-manager.ts:159


getAlgoNodeConfig(network, config): AlgoClientConfig

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

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

AlgoClientConfig

The AlgoNode client configuration

Example

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

src/types/client-manager.ts:545


getAlgodClient(config): AlgodClient

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

NameTypeDescription
configAlgoClientConfigThe config of the client

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();

src/types/client-manager.ts:590


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).

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();

src/types/client-manager.ts:608


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.

AlgoClientConfig

The Algod client configuration

Throws

Error if process.env.ALGOD_SERVER is not defined

Example

const config = ClientManager.getAlgodConfigFromEnvironment();

src/types/client-manager.ts:492


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.

AlgoConfig

The config for algod, indexer and kmd

Example

const config = ClientManager.getConfigFromEnvironmentOrLocalNet();

src/types/client-manager.ts:456


getDefaultLocalNetConfig(configOrPort): AlgoClientConfig

Returns the Algorand configuration to point to the default LocalNet.

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

AlgoClientConfig

The LocalNet client configuration

Example

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

src/types/client-manager.ts:561


getIndexerClient(config): IndexerClient

Returns an indexer SDK client that automatically retries on idempotent calls

NameTypeDescription
configAlgoClientConfigThe config of the client

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();

src/types/client-manager.ts:633


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).

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();

src/types/client-manager.ts:652


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.

AlgoClientConfig

The Indexer client configuration

Throws

Error if process.env.INDEXER_SERVER is not defined

Example

const config = ClientManager.getIndexerConfigFromEnvironment();

src/types/client-manager.ts:519


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.

NameTypeDescription
configAlgoClientConfigThe config for the client

KmdClient

The KMD client

Example

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

src/types/client-manager.ts:668


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).

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();

src/types/client-manager.ts:683