Skip to content

ClientManager

Defined in: src/client-manager.ts:47

Exposes access to various API clients.

new ClientManager(clientsOrConfig, algorandClient?): ClientManager

Defined in: src/client-manager.ts:73

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

The clients or config to use

AlgoConfig | AlgoSdkClients

AlgorandClient

ClientManager

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

get algod(): AlgodClient

Defined in: src/client-manager.ts:92

Returns an Algod API client.

AlgodClient

The Algod client


get indexer(): IndexerClient

Defined in: src/client-manager.ts:101

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

Error if no Indexer client is configured

IndexerClient

The Indexer client


get indexerIfPresent(): IndexerClient | undefined

Defined in: src/client-manager.ts:110

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

IndexerClient | undefined

The Indexer client or undefined


get kmd(): KmdClient

Defined in: src/client-manager.ts:119

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

Error if no KMD client is configured

KmdClient

The KMD client

getAppClientByCreatorAndName(params): Promise<AppClient>

Defined in: src/client-manager.ts:283

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

The parameters to create the app client

AppLookup

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

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name

ProgramSourceMap

Optional source map for the approval program

string | Arc56Contract | AppSpec

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

ProgramSourceMap

Optional source map for the clear state program

ReadableAddress

The address of the creator account for the app

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

boolean

Whether or not to ignore the AppDeployer lookup cache and force an on-chain lookup, default: use any cached value

Promise<AppClient>

The AppClient instance

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

getAppClientById(params): AppClient

Defined in: src/client-manager.ts:306

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

The parameters to create the app client

bigint

The ID of the app instance this client should make calls against.

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name

ProgramSourceMap

Optional source map for the approval program

string | Arc56Contract | AppSpec

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

ProgramSourceMap

Optional source map for the clear state program

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional 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

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

getAppClientByNetwork(params): Promise<AppClient>

Defined in: src/client-manager.ts:329

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.

The parameters to create the app client

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name

ProgramSourceMap

Optional source map for the approval program

string | Arc56Contract | AppSpec

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

ProgramSourceMap

Optional source map for the clear state program

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional 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

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

getAppFactory(params): AppFactory

Defined in: src/client-manager.ts:260

Returns a new AppFactory client

The parameters to create the app factory

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name.

string | Arc56Contract | AppSpec

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

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

boolean

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

TealTemplateParams

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

boolean

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

string

The version of app that is / will be deployed; defaults to 1.0

AppFactory

The AppFactory instance

const factory = clientManager.getAppFactory({
appSpec: '{/* ARC-56 or ARC-32 compatible JSON */}',
})
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' }
})

getTestNetDispenser(params): TestNetDispenserApiClient

Defined in: src/client-manager.ts:214

Returns a TestNet Dispenser API client.

Refer to docs on guidance to obtain an access token.

TestNetDispenserApiClientParams

An object containing parameters for the TestNetDispenserApiClient class.

TestNetDispenserApiClient

An instance of the TestNetDispenserApiClient class.

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

getTestNetDispenserFromEnvironment(params?): TestNetDispenserApiClient

Defined in: src/client-manager.ts:233

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.

Omit<TestNetDispenserApiClientParams, "authToken">

An object containing parameters for the TestNetDispenserApiClient class.

TestNetDispenserApiClient

An instance of the TestNetDispenserApiClient class.

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

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

Defined in: src/client-manager.ts:357

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

TClient extends TypedAppClient<InstanceType<TClient>>

TClient

The typed client type to use

The params to resolve the app by creator address and name

AppLookup

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

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name

ProgramSourceMap

Optional source map for the approval program

ProgramSourceMap

Optional source map for the clear state program

ReadableAddress

The address of the creator account for the app

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

boolean

Whether 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

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

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

Defined in: src/client-manager.ts:381

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

TClient extends TypedAppClient<InstanceType<TClient>>

TClient

The typed client type to use

The params to resolve the app by ID

bigint

The ID of the app instance this client should make calls against.

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name

ProgramSourceMap

Optional source map for the approval program

ProgramSourceMap

Optional source map for the clear state program

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional 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

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

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

Defined in: src/client-manager.ts:407

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.

TClient extends TypedAppClient<InstanceType<TClient>>

TClient

The typed client type to use

The params to resolve the app by network

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name

ProgramSourceMap

Optional source map for the approval program

ProgramSourceMap

Optional source map for the clear state program

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional 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

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

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

Defined in: src/client-manager.ts:430

Returns a new typed app factory.

TClient

TypedAppFactory<TClient>

The typed factory type to use

The params to resolve the factory by

string

Optional override for the app name; used for on-chain metadata and lookups. Defaults to the ARC-32/ARC-56 app spec name.

ReadableAddress

Optional address to use for the account to use as the default sender for calls.

TransactionSigner

Optional signer to use as the default signer for default sender calls (if not specified then the signer will be resolved from AlgorandClient).

boolean

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

TealTemplateParams

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

boolean

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

string

The version of app that is / will be deployed; defaults to 1.0

TClient

The typed client instance

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

isLocalNet(): Promise<boolean>

Defined in: src/client-manager.ts:170

Returns true if the current network is LocalNet.

Promise<boolean>

True if the current network is LocalNet.

const isLocalNet = await clientManager.isLocalNet()

isMainNet(): Promise<boolean>

Defined in: src/client-manager.ts:194

Returns true if the current network is MainNet.

Promise<boolean>

True if the current network is MainNet.

const isMainNet = await clientManager.isMainNet()

isTestNet(): Promise<boolean>

Defined in: src/client-manager.ts:182

Returns true if the current network is TestNet.

Promise<boolean>

True if the current network is TestNet.

const isTestNet = await clientManager.isTestNet()

network(): Promise<NetworkDetails>

Defined in: src/client-manager.ts:134

Get details about the current network.

Promise<NetworkDetails>

The current network details

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

static genesisIdIsLocalNet(genesisId): genesisId is “devnet-v1” | “sandnet-v1” | “dockernet-v1”

Defined in: src/client-manager.ts:158

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

string

The network genesis ID

genesisId is “devnet-v1” | “sandnet-v1” | “dockernet-v1”

Whether the given genesis ID is associated with a LocalNet network

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

static getAlgodClient(config): AlgodClient

Defined in: src/client-manager.ts:589

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

AlgoClientConfig

The config of the client

AlgodClient

The Algod client

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

static getAlgodClientFromEnvironment(): AlgodClient

Defined in: src/client-manager.ts:610

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

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

static getAlgodConfigFromEnvironment(): AlgoClientConfig

Defined in: src/client-manager.ts:491

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

Error if process.env.ALGOD_SERVER is not defined

const config = ClientManager.getAlgodConfigFromEnvironment()

static getAlgoNodeConfig(network, config): AlgoClientConfig

Defined in: src/client-manager.ts:544

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

Which network to connect to - TestNet or MainNet

"testnet" | "mainnet"

Which algod config to return - Algod or Indexer

"algod" | "indexer"

AlgoClientConfig

The AlgoNode client configuration

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

static getConfigFromEnvironmentOrLocalNet(): AlgoConfig

Defined in: src/client-manager.ts:455

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

const config = ClientManager.getConfigFromEnvironmentOrLocalNet()

static getDefaultLocalNetConfig(configOrPort): AlgoClientConfig

Defined in: src/client-manager.ts:560

Returns the Algorand configuration to point to the default LocalNet.

Which algod config to return - algod, kmd, or indexer OR a port number

number | "algod" | "indexer" | "kmd"

AlgoClientConfig

The LocalNet client configuration

const config = ClientManager.getDefaultLocalNetConfig('algod')

static getIndexerClient(config): IndexerClient

Defined in: src/client-manager.ts:635

Returns an indexer SDK client that automatically retries on idempotent calls

AlgoClientConfig

The config of the client

IndexerClient

The Indexer client

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

static getIndexerClientFromEnvironment(): IndexerClient

Defined in: src/client-manager.ts:657

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

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

static getIndexerConfigFromEnvironment(): AlgoClientConfig

Defined in: src/client-manager.ts:518

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

Error if process.env.INDEXER_SERVER is not defined

const config = ClientManager.getIndexerConfigFromEnvironment()

static getKmdClient(config): KmdClient

Defined in: src/client-manager.ts:673

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.

AlgoClientConfig

The config for the client

KmdClient

The KMD client

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

static getKmdClientFromEnvironment(): KmdClient

Defined in: src/client-manager.ts:693

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

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