@algorandfoundation/algokit-utils 10.0.0-alpha.12 → 10.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/algod-client/index.d.ts +2 -3
- package/algod-client/index.js +2 -5
- package/algod-client/index.mjs +2 -2
- package/indexer-client/index.d.ts +1 -2
- package/indexer-client/index.js +0 -5
- package/indexer-client/index.mjs +1 -2
- package/kmd-client/index.d.ts +1 -2
- package/kmd-client/index.js +0 -5
- package/kmd-client/index.mjs +1 -2
- package/package.json +1 -1
- package/packages/algod_client/src/apis/api-service.js +2 -2
- package/packages/algod_client/src/apis/api-service.mjs +2 -2
- package/packages/algod_client/src/core/model-runtime.js +2 -2
- package/packages/algod_client/src/core/model-runtime.js.map +1 -1
- package/packages/algod_client/src/core/model-runtime.mjs +2 -2
- package/packages/algod_client/src/core/model-runtime.mjs.map +1 -1
- package/packages/algod_client/src/models/simulate-request.js +1 -1
- package/packages/algod_client/src/models/simulate-request.mjs +1 -1
- package/packages/algod_client/src/models/simulate-response.d.ts +2 -1
- package/packages/algod_client/src/models/simulate-response.js +6 -1
- package/packages/algod_client/src/models/simulate-response.js.map +1 -1
- package/packages/algod_client/src/models/simulate-response.mjs +6 -2
- package/packages/algod_client/src/models/simulate-response.mjs.map +1 -1
- package/packages/indexer_client/src/core/model-runtime.js +0 -15
- package/packages/indexer_client/src/core/model-runtime.js.map +1 -1
- package/packages/indexer_client/src/core/model-runtime.mjs +1 -13
- package/packages/indexer_client/src/core/model-runtime.mjs.map +1 -1
- package/packages/kmd_client/src/core/model-runtime.js +2 -12
- package/packages/kmd_client/src/core/model-runtime.js.map +1 -1
- package/packages/kmd_client/src/core/model-runtime.mjs +3 -11
- package/packages/kmd_client/src/core/model-runtime.mjs.map +1 -1
- package/transactions/app-call.d.ts +1 -1
- package/transactions/app-call.js.map +1 -1
- package/transactions/app-call.mjs.map +1 -1
- package/transactions/method-call.d.ts +1 -1
- package/transactions/method-call.js.map +1 -1
- package/transactions/method-call.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +42 -42
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +43 -43
- package/types/app-client.d.ts +74 -74
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +1 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +25 -25
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs.map +1 -1
- package/types/app.d.ts +1 -1
- package/types/app.js.map +1 -1
- package/types/app.mjs.map +1 -1
- package/types/async-event-emitter.d.ts +3 -6
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.d.ts +1 -1
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +1 -1
- package/types/composer.js +3 -3
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +3 -3
- package/types/composer.mjs.map +1 -1
- package/types/debugging.d.ts +13 -9
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +0 -1
- package/types/lifecycle-events.js.map +1 -1
- package/types/lifecycle-events.mjs.map +1 -1
- package/types/transaction.d.ts +1 -1
- package/packages/algod_client/src/core/model-runtime.d.ts +0 -10
- package/packages/indexer_client/src/core/model-runtime.d.ts +0 -10
- package/packages/kmd_client/src/core/model-runtime.d.ts +0 -10
- package/types/expand.d.ts +0 -9
- package/types/expand.js +0 -0
- package/types/expand.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-manager.js","names":["genesisIdIsLocalNet","TestNetDispenserApiClient","AppFactory","AppClient","AlgodClient","Config","IndexerClient","KmdClient"],"sources":["../../src/types/client-manager.ts"],"sourcesContent":["import { AlgodClient, SuggestedParams } from '@algorandfoundation/algokit-algod-client'\nimport { IndexerClient } from '@algorandfoundation/algokit-indexer-client'\nimport { KmdClient } from '@algorandfoundation/algokit-kmd-client'\nimport { Config } from '../config'\nimport { type AlgorandClient } from './algorand-client'\nimport { AppClient, AppClientParams, ResolveAppClientByCreatorAndName } from './app-client'\nimport { AppFactory, AppFactoryParams } from './app-factory'\nimport { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './dispenser-client'\nimport { Expand } from './expand'\nimport { AlgoClientConfig, AlgoConfig, NetworkDetails, genesisIdIsLocalNet } from './network-client'\n\n/** Clients from algosdk that interact with the official Algorand APIs */\nexport interface AlgoSdkClients {\n /** Algod client, see https://dev.algorand.co/reference/rest-apis/algod/ */\n algod: AlgodClient\n /** Optional indexer client, see https://dev.algorand.co/reference/rest-apis/indexer */\n indexer?: IndexerClient\n /** Optional KMD client, see https://dev.algorand.co/reference/rest-apis/kmd/ */\n kmd?: KmdClient\n}\n\n/** Params to get an app factory from `ClientManager`. */\nexport type ClientAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand'>>\n\n/** Params to get an app client by creator address and name from `ClientManager`. */\nexport type ClientResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand'>>\n\n/** Params to get an app client by ID from `ClientManager`. */\nexport type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand'>>\n\n/** Params to get an app client by network from `ClientManager`. */\nexport type ClientAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appId'>>\n\n/** Params to get a typed app client by creator address and name from `ClientManager`. */\nexport type ClientTypedAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by ID from `ClientManager`. */\nexport type ClientTypedAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by network from `ClientManager`. */\nexport type ClientTypedAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'>>\n\n/** Params to get a typed app factory from `ClientManager`. */\nexport type ClientTypedAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand' | 'appSpec'>>\n\n/** Exposes access to various API clients. */\nexport class ClientManager {\n private _algod: AlgodClient\n private _indexer?: IndexerClient\n private _kmd?: KmdClient\n private _algorand?: AlgorandClient\n\n /**\n * algosdk clients or config for interacting with the official Algorand APIs.\n * @param clientsOrConfig The clients or config to use\n * @example Algod client only\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient })\n * ```\n * @example All clients\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })\n * ```\n * @example Algod config only\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig })\n * ```\n * @example All client configs\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })\n * ```\n */\n constructor(clientsOrConfig: AlgoConfig | AlgoSdkClients, algorandClient?: AlgorandClient) {\n const _clients =\n 'algod' in clientsOrConfig\n ? clientsOrConfig\n : {\n algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),\n indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,\n kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,\n }\n this._algod = _clients.algod\n this._indexer = _clients.indexer\n this._kmd = _clients.kmd\n this._algorand = algorandClient\n }\n\n /**\n * Returns an Algod API client.\n * @returns The Algod client\n */\n public get algod(): AlgodClient {\n return this._algod\n }\n\n /**\n * Returns an Indexer API client or throws an error if it's not been provided.\n * @returns The Indexer client\n * @throws Error if no Indexer client is configured\n */\n public get indexer(): IndexerClient {\n if (!this._indexer) throw new Error('Attempt to use Indexer client in AlgoKit instance with no Indexer configured')\n return this._indexer\n }\n\n /**\n * Returns an Indexer API client or `undefined` if it's not been provided.\n * @returns The Indexer client or `undefined`\n */\n public get indexerIfPresent(): IndexerClient | undefined {\n return this._indexer\n }\n\n /**\n * Returns a KMD API client or throws an error if it's not been provided.\n * @returns The KMD client\n * @throws Error if no KMD client is configured\n */\n public get kmd(): KmdClient {\n if (!this._kmd) throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n return this._kmd\n }\n\n private _getNetworkPromise: Promise<SuggestedParams> | undefined\n /**\n * Get details about the current network.\n * @example Getting genesis ID\n * ```typescript\n * const network = await networkClient.network()\n * const genesisId = network.genesisId\n * ```\n * @returns The current network details\n */\n public async network(): Promise<NetworkDetails> {\n if (!this._getNetworkPromise) {\n this._getNetworkPromise = this._algod.suggestedParams()\n }\n\n const params = await this._getNetworkPromise\n return {\n isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisId ?? 'unknown'),\n isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisId ?? 'unknown'),\n isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisId ?? 'unknown'),\n genesisId: params.genesisId ?? 'unknown',\n genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',\n }\n }\n\n /**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n * @example\n * ```typescript\n * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')\n * ```\n */\n public static genesisIdIsLocalNet(genesisId: string) {\n return genesisIdIsLocalNet(genesisId)\n }\n\n /**\n * Returns true if the current network is LocalNet.\n * @returns True if the current network is LocalNet.\n * @example\n * ```typescript\n * const isLocalNet = await clientManager.isLocalNet()\n * ```\n */\n public async isLocalNet() {\n return (await this.network()).isLocalNet\n }\n\n /**\n * Returns true if the current network is TestNet.\n * @returns True if the current network is TestNet.\n * @example\n * ```typescript\n * const isTestNet = await clientManager.isTestNet()\n * ```\n */\n public async isTestNet() {\n return (await this.network()).isTestNet\n }\n\n /**\n * Returns true if the current network is MainNet.\n * @returns True if the current network is MainNet.\n * @example\n * ```typescript\n * const isMainNet = await clientManager.isMainNet()\n * ```\n */\n public async isMainNet() {\n return (await this.network()).isMainNet\n }\n\n /**\n * Returns a TestNet Dispenser API client.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenser(\n * {\n * authToken: 'your_auth_token',\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenser(params: TestNetDispenserApiClientParams) {\n return new TestNetDispenserApiClient(params)\n }\n\n /**\n * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenserFromEnvironment(\n * {\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenserFromEnvironment(params?: Omit<TestNetDispenserApiClientParams, 'authToken'>) {\n return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined)\n }\n\n /**\n * Returns a new `AppFactory` client\n * @param params The parameters to create the app factory\n * @example Basic example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\/}',\n * })\n * ```\n * @example Advanced example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,\n * defaultSender: \"SENDERADDRESS\",\n * appName: \"OverriddenAppName\",\n * version: \"2.0.0\",\n * updatable: true,\n * deletable: false,\n * deployTimeParams: { ONE: 1, TWO: 'value' }\n * })\n * ```\n * @returns The `AppFactory` instance\n */\n public getAppFactory(params: ClientAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new AppFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * This method resolves the app ID by looking up the creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByCreatorAndName({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by looking for app ID of named app by this creator\n * creatorAddress: 'CREATORADDRESS',\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientByCreatorAndName(params: ClientResolveAppClientByCreatorAndNameParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return AppClient.fromCreatorAndName({\n ...params,\n algorand: this._algorand,\n })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientById({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * appId: 12345n,\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientById(params: ClientAppClientParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return new AppClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.\n * This method resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByNetwork({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by using ARC-56 spec to find app ID for current network\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public async getAppClientByNetwork(params: ClientAppClientByNetworkParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return AppClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by creator address and name.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by creator address and name\n * @example Use name in ARC-32 / ARC-56 app spec\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * defaultSender: alice,\n * })\n * ```\n * @example Specify name\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * name: \"contract-name\",\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public async getTypedAppClientByCreatorAndName<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientByCreatorAndNameParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromCreatorAndName({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by app ID.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by ID\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientById(MyContractClient, {\n * appId: 12345n,\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientById<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return new typedClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by network\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientByNetwork<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params?: ClientTypedAppClientByNetworkParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed app factory.\n * @param typedFactory The typed factory type to use\n * @param params The params to resolve the factory by\n * @example\n * ```typescript\n * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {\n * sender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppFactory<TClient>(typedFactory: TypedAppFactory<TClient>, params?: ClientTypedAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new typedFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)\n *\n * 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`.\n *\n * 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`.\n *\n * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @example\n * ```typescript\n * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()\n * ```\n * @returns The config for algod, indexer and kmd\n */\n public static getConfigFromEnvironmentOrLocalNet(): AlgoConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead')\n }\n const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER\n ? [\n ClientManager.getAlgodConfigFromEnvironment(),\n process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,\n !process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')\n ? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }\n : undefined,\n ]\n : [\n ClientManager.getDefaultLocalNetConfig('algod'),\n ClientManager.getDefaultLocalNetConfig('indexer'),\n ClientManager.getDefaultLocalNetConfig('kmd'),\n ]\n\n return {\n algodConfig,\n indexerConfig,\n kmdConfig,\n }\n }\n\n /**\n * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)\n *\n * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n * @returns The Algod client configuration\n * @throws Error if `process.env.ALGOD_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getAlgodConfigFromEnvironment()\n * ```\n */\n public static getAlgodConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.ALGOD_SERVER) {\n throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables')\n }\n\n return {\n server: process.env.ALGOD_SERVER,\n port: process.env.ALGOD_PORT,\n token: process.env.ALGOD_TOKEN,\n }\n }\n\n /**\n * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).\n *\n * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n * @returns The Indexer client configuration\n * @throws Error if `process.env.INDEXER_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getIndexerConfigFromEnvironment()\n * ```\n */\n public static getIndexerConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.INDEXER_SERVER) {\n throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables')\n }\n\n return {\n server: process.env.INDEXER_SERVER,\n port: process.env.INDEXER_PORT,\n token: process.env.INDEXER_TOKEN,\n }\n }\n\n /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.\n *\n * @param network Which network to connect to - TestNet or MainNet\n * @param config Which algod config to return - Algod or Indexer\n * @returns The AlgoNode client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')\n * ```\n */\n public static getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig {\n return {\n server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,\n port: 443,\n }\n }\n\n /** Returns the Algorand configuration to point to the default LocalNet.\n *\n * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number\n * @returns The LocalNet client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getDefaultLocalNetConfig('algod')\n * ```\n */\n public static getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig {\n return {\n server: `http://localhost`,\n port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,\n token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n }\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls.\n *\n * @param config The config of the client\n * @returns The Algod client\n * @example AlgoNode (testnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClient(config: AlgoClientConfig): AlgodClient {\n const { token, server, port } = config\n return new AlgodClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Algod client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN\n * const algod = ClientManager.getAlgodClientFromEnvironment()\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClientFromEnvironment(): AlgodClient {\n return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment())\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls\n *\n * @param config The config of the client\n * @returns The Indexer client\n * @example AlgoNode (testnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClient(config: AlgoClientConfig): IndexerClient {\n const { token, server, port } = config\n return new IndexerClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Indexer client\n * @example\n *\n * ```typescript\n * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN\n * const indexer = ClientManager.getIndexerClientFromEnvironment()\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClientFromEnvironment(): IndexerClient {\n return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment())\n }\n\n /**\n * Returns a KMD SDK client.\n *\n * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.\n *\n * @param config The config for the client\n * @returns The KMD client\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * ```\n */\n public static getKmdClient(config: AlgoClientConfig): KmdClient {\n const { token, server, port } = config\n return new KmdClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The KMD client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN\n * const kmd = ClientManager.getKmdClientFromEnvironment()\n * ```\n */\n public static getKmdClientFromEnvironment(): KmdClient {\n // We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions\n // (e.g. same token and server as algod and port 4002 by default)\n return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' })\n }\n}\n\n/**\n * Interface to identify a typed client that can be used to interact with an application.\n */\nexport interface TypedAppClient<TClient> {\n new (params: Omit<AppClientParams, 'appSpec'>): TClient\n fromNetwork(params: Omit<AppClientParams, 'appId' | 'appSpec'>): Promise<TClient>\n fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<TClient>\n}\n\n/**\n * Interface to identify a typed factory that can be used to create and deploy an application.\n */\nexport interface TypedAppFactory<TClient> {\n new (params: Omit<AppFactoryParams, 'appSpec'>): TClient\n}\n"],"mappings":";;;;;;;;;;;AA8CA,IAAa,gBAAb,MAAa,cAAc;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;;;;;;;;;;;;;;CAsBR,YAAY,iBAA8C,gBAAiC;EACzF,MAAM,WACJ,WAAW,kBACP,kBACA;GACE,OAAO,cAAc,eAAe,gBAAgB,YAAY;GAChE,SAAS,gBAAgB,gBAAgB,cAAc,iBAAiB,gBAAgB,cAAc,GAAG;GACzG,KAAK,gBAAgB,YAAY,cAAc,aAAa,gBAAgB,UAAU,GAAG;GAC1F;AACP,OAAK,SAAS,SAAS;AACvB,OAAK,WAAW,SAAS;AACzB,OAAK,OAAO,SAAS;AACrB,OAAK,YAAY;;;;;;CAOnB,IAAW,QAAqB;AAC9B,SAAO,KAAK;;;;;;;CAQd,IAAW,UAAyB;AAClC,MAAI,CAAC,KAAK,SAAU,OAAM,IAAI,MAAM,+EAA+E;AACnH,SAAO,KAAK;;;;;;CAOd,IAAW,mBAA8C;AACvD,SAAO,KAAK;;;;;;;CAQd,IAAW,MAAiB;AAC1B,MAAI,CAAC,KAAK,KAAM,OAAM,IAAI,MAAM,uEAAuE;AACvG,SAAO,KAAK;;CAGd,AAAQ;;;;;;;;;;CAUR,MAAa,UAAmC;AAC9C,MAAI,CAAC,KAAK,mBACR,MAAK,qBAAqB,KAAK,OAAO,iBAAiB;EAGzD,MAAM,SAAS,MAAM,KAAK;AAC1B,SAAO;GACL,WAAW;IAAC;IAAgB;IAAc;IAAU,CAAC,SAA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,cAAc,eAAe,cAAc,+BAA+B,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAwBpF,OAAc,iBAAiB,QAAyC;EACtE,MAAM,EAAE,OAAO,QAAQ,SAAS;AAChC,SAAO,IAAIC,+BAAc;GACvB,SAAS;GACT;GACA;GACA,QAAQD,sBAAO;GAChB,CAAC;;;;;;;;;;;;;;CAeJ,OAAc,kCAAiD;AAC7D,SAAO,cAAc,iBAAiB,cAAc,iCAAiC,CAAC;;;;;;;;;;;;;;CAexF,OAAc,aAAa,QAAqC;EAC9D,MAAM,EAAE,OAAO,QAAQ,SAAS;AAChC,SAAO,IAAIE,2BAAU;GACnB,SAAS;GACT;GACA;GACA,QAAQF,sBAAO;GAChB,CAAC;;;;;;;;;;;;CAaJ,OAAc,8BAAyC;AAGrD,SAAO,cAAc,aAAa;GAAE,GAAG,cAAc,+BAA+B;GAAE,MAAM,SAAS,KAAK,YAAY;GAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"client-manager.js","names":["genesisIdIsLocalNet","TestNetDispenserApiClient","AppFactory","AppClient","AlgodClient","Config","IndexerClient","KmdClient"],"sources":["../../src/types/client-manager.ts"],"sourcesContent":["import { AlgodClient, SuggestedParams } from '@algorandfoundation/algokit-algod-client'\nimport { Expand } from '@algorandfoundation/algokit-common'\nimport { IndexerClient } from '@algorandfoundation/algokit-indexer-client'\nimport { KmdClient } from '@algorandfoundation/algokit-kmd-client'\nimport { Config } from '../config'\nimport { type AlgorandClient } from './algorand-client'\nimport { AppClient, AppClientParams, ResolveAppClientByCreatorAndName } from './app-client'\nimport { AppFactory, AppFactoryParams } from './app-factory'\nimport { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './dispenser-client'\nimport { AlgoClientConfig, AlgoConfig, NetworkDetails, genesisIdIsLocalNet } from './network-client'\n\n/** Clients from algosdk that interact with the official Algorand APIs */\nexport interface AlgoSdkClients {\n /** Algod client, see https://dev.algorand.co/reference/rest-apis/algod/ */\n algod: AlgodClient\n /** Optional indexer client, see https://dev.algorand.co/reference/rest-apis/indexer */\n indexer?: IndexerClient\n /** Optional KMD client, see https://dev.algorand.co/reference/rest-apis/kmd/ */\n kmd?: KmdClient\n}\n\n/** Params to get an app factory from `ClientManager`. */\nexport type ClientAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand'>>\n\n/** Params to get an app client by creator address and name from `ClientManager`. */\nexport type ClientResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand'>>\n\n/** Params to get an app client by ID from `ClientManager`. */\nexport type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand'>>\n\n/** Params to get an app client by network from `ClientManager`. */\nexport type ClientAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appId'>>\n\n/** Params to get a typed app client by creator address and name from `ClientManager`. */\nexport type ClientTypedAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by ID from `ClientManager`. */\nexport type ClientTypedAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by network from `ClientManager`. */\nexport type ClientTypedAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'>>\n\n/** Params to get a typed app factory from `ClientManager`. */\nexport type ClientTypedAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand' | 'appSpec'>>\n\n/** Exposes access to various API clients. */\nexport class ClientManager {\n private _algod: AlgodClient\n private _indexer?: IndexerClient\n private _kmd?: KmdClient\n private _algorand?: AlgorandClient\n\n /**\n * algosdk clients or config for interacting with the official Algorand APIs.\n * @param clientsOrConfig The clients or config to use\n * @example Algod client only\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient })\n * ```\n * @example All clients\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })\n * ```\n * @example Algod config only\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig })\n * ```\n * @example All client configs\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })\n * ```\n */\n constructor(clientsOrConfig: AlgoConfig | AlgoSdkClients, algorandClient?: AlgorandClient) {\n const _clients =\n 'algod' in clientsOrConfig\n ? clientsOrConfig\n : {\n algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),\n indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,\n kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,\n }\n this._algod = _clients.algod\n this._indexer = _clients.indexer\n this._kmd = _clients.kmd\n this._algorand = algorandClient\n }\n\n /**\n * Returns an Algod API client.\n * @returns The Algod client\n */\n public get algod(): AlgodClient {\n return this._algod\n }\n\n /**\n * Returns an Indexer API client or throws an error if it's not been provided.\n * @returns The Indexer client\n * @throws Error if no Indexer client is configured\n */\n public get indexer(): IndexerClient {\n if (!this._indexer) throw new Error('Attempt to use Indexer client in AlgoKit instance with no Indexer configured')\n return this._indexer\n }\n\n /**\n * Returns an Indexer API client or `undefined` if it's not been provided.\n * @returns The Indexer client or `undefined`\n */\n public get indexerIfPresent(): IndexerClient | undefined {\n return this._indexer\n }\n\n /**\n * Returns a KMD API client or throws an error if it's not been provided.\n * @returns The KMD client\n * @throws Error if no KMD client is configured\n */\n public get kmd(): KmdClient {\n if (!this._kmd) throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n return this._kmd\n }\n\n private _getNetworkPromise: Promise<SuggestedParams> | undefined\n /**\n * Get details about the current network.\n * @example Getting genesis ID\n * ```typescript\n * const network = await networkClient.network()\n * const genesisId = network.genesisId\n * ```\n * @returns The current network details\n */\n public async network(): Promise<NetworkDetails> {\n if (!this._getNetworkPromise) {\n this._getNetworkPromise = this._algod.suggestedParams()\n }\n\n const params = await this._getNetworkPromise\n return {\n isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisId ?? 'unknown'),\n isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisId ?? 'unknown'),\n isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisId ?? 'unknown'),\n genesisId: params.genesisId ?? 'unknown',\n genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',\n }\n }\n\n /**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n * @example\n * ```typescript\n * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')\n * ```\n */\n public static genesisIdIsLocalNet(genesisId: string) {\n return genesisIdIsLocalNet(genesisId)\n }\n\n /**\n * Returns true if the current network is LocalNet.\n * @returns True if the current network is LocalNet.\n * @example\n * ```typescript\n * const isLocalNet = await clientManager.isLocalNet()\n * ```\n */\n public async isLocalNet() {\n return (await this.network()).isLocalNet\n }\n\n /**\n * Returns true if the current network is TestNet.\n * @returns True if the current network is TestNet.\n * @example\n * ```typescript\n * const isTestNet = await clientManager.isTestNet()\n * ```\n */\n public async isTestNet() {\n return (await this.network()).isTestNet\n }\n\n /**\n * Returns true if the current network is MainNet.\n * @returns True if the current network is MainNet.\n * @example\n * ```typescript\n * const isMainNet = await clientManager.isMainNet()\n * ```\n */\n public async isMainNet() {\n return (await this.network()).isMainNet\n }\n\n /**\n * Returns a TestNet Dispenser API client.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenser(\n * {\n * authToken: 'your_auth_token',\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenser(params: TestNetDispenserApiClientParams) {\n return new TestNetDispenserApiClient(params)\n }\n\n /**\n * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenserFromEnvironment(\n * {\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenserFromEnvironment(params?: Omit<TestNetDispenserApiClientParams, 'authToken'>) {\n return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined)\n }\n\n /**\n * Returns a new `AppFactory` client\n * @param params The parameters to create the app factory\n * @example Basic example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\/}',\n * })\n * ```\n * @example Advanced example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,\n * defaultSender: \"SENDERADDRESS\",\n * appName: \"OverriddenAppName\",\n * version: \"2.0.0\",\n * updatable: true,\n * deletable: false,\n * deployTimeParams: { ONE: 1, TWO: 'value' }\n * })\n * ```\n * @returns The `AppFactory` instance\n */\n public getAppFactory(params: ClientAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new AppFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * This method resolves the app ID by looking up the creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByCreatorAndName({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by looking for app ID of named app by this creator\n * creatorAddress: 'CREATORADDRESS',\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientByCreatorAndName(params: ClientResolveAppClientByCreatorAndNameParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return AppClient.fromCreatorAndName({\n ...params,\n algorand: this._algorand,\n })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientById({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * appId: 12345n,\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientById(params: ClientAppClientParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return new AppClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.\n * This method resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByNetwork({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by using ARC-56 spec to find app ID for current network\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public async getAppClientByNetwork(params: ClientAppClientByNetworkParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return AppClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by creator address and name.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by creator address and name\n * @example Use name in ARC-32 / ARC-56 app spec\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * defaultSender: alice,\n * })\n * ```\n * @example Specify name\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * name: \"contract-name\",\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public async getTypedAppClientByCreatorAndName<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientByCreatorAndNameParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromCreatorAndName({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by app ID.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by ID\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientById(MyContractClient, {\n * appId: 12345n,\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientById<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return new typedClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by network\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientByNetwork<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params?: ClientTypedAppClientByNetworkParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed app factory.\n * @param typedFactory The typed factory type to use\n * @param params The params to resolve the factory by\n * @example\n * ```typescript\n * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {\n * sender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppFactory<TClient>(typedFactory: TypedAppFactory<TClient>, params?: ClientTypedAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new typedFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)\n *\n * 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`.\n *\n * 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`.\n *\n * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @example\n * ```typescript\n * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()\n * ```\n * @returns The config for algod, indexer and kmd\n */\n public static getConfigFromEnvironmentOrLocalNet(): AlgoConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead')\n }\n const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER\n ? [\n ClientManager.getAlgodConfigFromEnvironment(),\n process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,\n !process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')\n ? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }\n : undefined,\n ]\n : [\n ClientManager.getDefaultLocalNetConfig('algod'),\n ClientManager.getDefaultLocalNetConfig('indexer'),\n ClientManager.getDefaultLocalNetConfig('kmd'),\n ]\n\n return {\n algodConfig,\n indexerConfig,\n kmdConfig,\n }\n }\n\n /**\n * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)\n *\n * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n * @returns The Algod client configuration\n * @throws Error if `process.env.ALGOD_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getAlgodConfigFromEnvironment()\n * ```\n */\n public static getAlgodConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.ALGOD_SERVER) {\n throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables')\n }\n\n return {\n server: process.env.ALGOD_SERVER,\n port: process.env.ALGOD_PORT,\n token: process.env.ALGOD_TOKEN,\n }\n }\n\n /**\n * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).\n *\n * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n * @returns The Indexer client configuration\n * @throws Error if `process.env.INDEXER_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getIndexerConfigFromEnvironment()\n * ```\n */\n public static getIndexerConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.INDEXER_SERVER) {\n throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables')\n }\n\n return {\n server: process.env.INDEXER_SERVER,\n port: process.env.INDEXER_PORT,\n token: process.env.INDEXER_TOKEN,\n }\n }\n\n /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.\n *\n * @param network Which network to connect to - TestNet or MainNet\n * @param config Which algod config to return - Algod or Indexer\n * @returns The AlgoNode client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')\n * ```\n */\n public static getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig {\n return {\n server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,\n port: 443,\n }\n }\n\n /** Returns the Algorand configuration to point to the default LocalNet.\n *\n * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number\n * @returns The LocalNet client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getDefaultLocalNetConfig('algod')\n * ```\n */\n public static getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig {\n return {\n server: `http://localhost`,\n port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,\n token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n }\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls.\n *\n * @param config The config of the client\n * @returns The Algod client\n * @example AlgoNode (testnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClient(config: AlgoClientConfig): AlgodClient {\n const { token, server, port } = config\n return new AlgodClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Algod client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN\n * const algod = ClientManager.getAlgodClientFromEnvironment()\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClientFromEnvironment(): AlgodClient {\n return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment())\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls\n *\n * @param config The config of the client\n * @returns The Indexer client\n * @example AlgoNode (testnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClient(config: AlgoClientConfig): IndexerClient {\n const { token, server, port } = config\n return new IndexerClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Indexer client\n * @example\n *\n * ```typescript\n * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN\n * const indexer = ClientManager.getIndexerClientFromEnvironment()\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClientFromEnvironment(): IndexerClient {\n return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment())\n }\n\n /**\n * Returns a KMD SDK client.\n *\n * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.\n *\n * @param config The config for the client\n * @returns The KMD client\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * ```\n */\n public static getKmdClient(config: AlgoClientConfig): KmdClient {\n const { token, server, port } = config\n return new KmdClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The KMD client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN\n * const kmd = ClientManager.getKmdClientFromEnvironment()\n * ```\n */\n public static getKmdClientFromEnvironment(): KmdClient {\n // We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions\n // (e.g. same token and server as algod and port 4002 by default)\n return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' })\n }\n}\n\n/**\n * Interface to identify a typed client that can be used to interact with an application.\n */\nexport interface TypedAppClient<TClient> {\n new (params: Omit<AppClientParams, 'appSpec'>): TClient\n fromNetwork(params: Omit<AppClientParams, 'appId' | 'appSpec'>): Promise<TClient>\n fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<TClient>\n}\n\n/**\n * Interface to identify a typed factory that can be used to create and deploy an application.\n */\nexport interface TypedAppFactory<TClient> {\n new (params: Omit<AppFactoryParams, 'appSpec'>): TClient\n}\n"],"mappings":";;;;;;;;;;;AA8CA,IAAa,gBAAb,MAAa,cAAc;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;;;;;;;;;;;;;;CAsBR,YAAY,iBAA8C,gBAAiC;EACzF,MAAM,WACJ,WAAW,kBACP,kBACA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AAyC;AAGrD,SAAO,cAAc,aAAa;GAAE,GAAG,cAAc,+BAA+B;GAAE,MAAM,SAAS,KAAK,YAAY;GAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-manager.mjs","names":[],"sources":["../../src/types/client-manager.ts"],"sourcesContent":["import { AlgodClient, SuggestedParams } from '@algorandfoundation/algokit-algod-client'\nimport { IndexerClient } from '@algorandfoundation/algokit-indexer-client'\nimport { KmdClient } from '@algorandfoundation/algokit-kmd-client'\nimport { Config } from '../config'\nimport { type AlgorandClient } from './algorand-client'\nimport { AppClient, AppClientParams, ResolveAppClientByCreatorAndName } from './app-client'\nimport { AppFactory, AppFactoryParams } from './app-factory'\nimport { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './dispenser-client'\nimport { Expand } from './expand'\nimport { AlgoClientConfig, AlgoConfig, NetworkDetails, genesisIdIsLocalNet } from './network-client'\n\n/** Clients from algosdk that interact with the official Algorand APIs */\nexport interface AlgoSdkClients {\n /** Algod client, see https://dev.algorand.co/reference/rest-apis/algod/ */\n algod: AlgodClient\n /** Optional indexer client, see https://dev.algorand.co/reference/rest-apis/indexer */\n indexer?: IndexerClient\n /** Optional KMD client, see https://dev.algorand.co/reference/rest-apis/kmd/ */\n kmd?: KmdClient\n}\n\n/** Params to get an app factory from `ClientManager`. */\nexport type ClientAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand'>>\n\n/** Params to get an app client by creator address and name from `ClientManager`. */\nexport type ClientResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand'>>\n\n/** Params to get an app client by ID from `ClientManager`. */\nexport type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand'>>\n\n/** Params to get an app client by network from `ClientManager`. */\nexport type ClientAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appId'>>\n\n/** Params to get a typed app client by creator address and name from `ClientManager`. */\nexport type ClientTypedAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by ID from `ClientManager`. */\nexport type ClientTypedAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by network from `ClientManager`. */\nexport type ClientTypedAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'>>\n\n/** Params to get a typed app factory from `ClientManager`. */\nexport type ClientTypedAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand' | 'appSpec'>>\n\n/** Exposes access to various API clients. */\nexport class ClientManager {\n private _algod: AlgodClient\n private _indexer?: IndexerClient\n private _kmd?: KmdClient\n private _algorand?: AlgorandClient\n\n /**\n * algosdk clients or config for interacting with the official Algorand APIs.\n * @param clientsOrConfig The clients or config to use\n * @example Algod client only\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient })\n * ```\n * @example All clients\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })\n * ```\n * @example Algod config only\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig })\n * ```\n * @example All client configs\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })\n * ```\n */\n constructor(clientsOrConfig: AlgoConfig | AlgoSdkClients, algorandClient?: AlgorandClient) {\n const _clients =\n 'algod' in clientsOrConfig\n ? clientsOrConfig\n : {\n algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),\n indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,\n kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,\n }\n this._algod = _clients.algod\n this._indexer = _clients.indexer\n this._kmd = _clients.kmd\n this._algorand = algorandClient\n }\n\n /**\n * Returns an Algod API client.\n * @returns The Algod client\n */\n public get algod(): AlgodClient {\n return this._algod\n }\n\n /**\n * Returns an Indexer API client or throws an error if it's not been provided.\n * @returns The Indexer client\n * @throws Error if no Indexer client is configured\n */\n public get indexer(): IndexerClient {\n if (!this._indexer) throw new Error('Attempt to use Indexer client in AlgoKit instance with no Indexer configured')\n return this._indexer\n }\n\n /**\n * Returns an Indexer API client or `undefined` if it's not been provided.\n * @returns The Indexer client or `undefined`\n */\n public get indexerIfPresent(): IndexerClient | undefined {\n return this._indexer\n }\n\n /**\n * Returns a KMD API client or throws an error if it's not been provided.\n * @returns The KMD client\n * @throws Error if no KMD client is configured\n */\n public get kmd(): KmdClient {\n if (!this._kmd) throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n return this._kmd\n }\n\n private _getNetworkPromise: Promise<SuggestedParams> | undefined\n /**\n * Get details about the current network.\n * @example Getting genesis ID\n * ```typescript\n * const network = await networkClient.network()\n * const genesisId = network.genesisId\n * ```\n * @returns The current network details\n */\n public async network(): Promise<NetworkDetails> {\n if (!this._getNetworkPromise) {\n this._getNetworkPromise = this._algod.suggestedParams()\n }\n\n const params = await this._getNetworkPromise\n return {\n isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisId ?? 'unknown'),\n isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisId ?? 'unknown'),\n isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisId ?? 'unknown'),\n genesisId: params.genesisId ?? 'unknown',\n genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',\n }\n }\n\n /**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n * @example\n * ```typescript\n * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')\n * ```\n */\n public static genesisIdIsLocalNet(genesisId: string) {\n return genesisIdIsLocalNet(genesisId)\n }\n\n /**\n * Returns true if the current network is LocalNet.\n * @returns True if the current network is LocalNet.\n * @example\n * ```typescript\n * const isLocalNet = await clientManager.isLocalNet()\n * ```\n */\n public async isLocalNet() {\n return (await this.network()).isLocalNet\n }\n\n /**\n * Returns true if the current network is TestNet.\n * @returns True if the current network is TestNet.\n * @example\n * ```typescript\n * const isTestNet = await clientManager.isTestNet()\n * ```\n */\n public async isTestNet() {\n return (await this.network()).isTestNet\n }\n\n /**\n * Returns true if the current network is MainNet.\n * @returns True if the current network is MainNet.\n * @example\n * ```typescript\n * const isMainNet = await clientManager.isMainNet()\n * ```\n */\n public async isMainNet() {\n return (await this.network()).isMainNet\n }\n\n /**\n * Returns a TestNet Dispenser API client.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenser(\n * {\n * authToken: 'your_auth_token',\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenser(params: TestNetDispenserApiClientParams) {\n return new TestNetDispenserApiClient(params)\n }\n\n /**\n * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenserFromEnvironment(\n * {\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenserFromEnvironment(params?: Omit<TestNetDispenserApiClientParams, 'authToken'>) {\n return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined)\n }\n\n /**\n * Returns a new `AppFactory` client\n * @param params The parameters to create the app factory\n * @example Basic example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\/}',\n * })\n * ```\n * @example Advanced example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,\n * defaultSender: \"SENDERADDRESS\",\n * appName: \"OverriddenAppName\",\n * version: \"2.0.0\",\n * updatable: true,\n * deletable: false,\n * deployTimeParams: { ONE: 1, TWO: 'value' }\n * })\n * ```\n * @returns The `AppFactory` instance\n */\n public getAppFactory(params: ClientAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new AppFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * This method resolves the app ID by looking up the creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByCreatorAndName({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by looking for app ID of named app by this creator\n * creatorAddress: 'CREATORADDRESS',\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientByCreatorAndName(params: ClientResolveAppClientByCreatorAndNameParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return AppClient.fromCreatorAndName({\n ...params,\n algorand: this._algorand,\n })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientById({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * appId: 12345n,\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientById(params: ClientAppClientParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return new AppClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.\n * This method resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByNetwork({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by using ARC-56 spec to find app ID for current network\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public async getAppClientByNetwork(params: ClientAppClientByNetworkParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return AppClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by creator address and name.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by creator address and name\n * @example Use name in ARC-32 / ARC-56 app spec\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * defaultSender: alice,\n * })\n * ```\n * @example Specify name\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * name: \"contract-name\",\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public async getTypedAppClientByCreatorAndName<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientByCreatorAndNameParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromCreatorAndName({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by app ID.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by ID\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientById(MyContractClient, {\n * appId: 12345n,\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientById<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return new typedClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by network\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientByNetwork<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params?: ClientTypedAppClientByNetworkParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed app factory.\n * @param typedFactory The typed factory type to use\n * @param params The params to resolve the factory by\n * @example\n * ```typescript\n * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {\n * sender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppFactory<TClient>(typedFactory: TypedAppFactory<TClient>, params?: ClientTypedAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new typedFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)\n *\n * 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`.\n *\n * 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`.\n *\n * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @example\n * ```typescript\n * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()\n * ```\n * @returns The config for algod, indexer and kmd\n */\n public static getConfigFromEnvironmentOrLocalNet(): AlgoConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead')\n }\n const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER\n ? [\n ClientManager.getAlgodConfigFromEnvironment(),\n process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,\n !process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')\n ? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }\n : undefined,\n ]\n : [\n ClientManager.getDefaultLocalNetConfig('algod'),\n ClientManager.getDefaultLocalNetConfig('indexer'),\n ClientManager.getDefaultLocalNetConfig('kmd'),\n ]\n\n return {\n algodConfig,\n indexerConfig,\n kmdConfig,\n }\n }\n\n /**\n * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)\n *\n * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n * @returns The Algod client configuration\n * @throws Error if `process.env.ALGOD_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getAlgodConfigFromEnvironment()\n * ```\n */\n public static getAlgodConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.ALGOD_SERVER) {\n throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables')\n }\n\n return {\n server: process.env.ALGOD_SERVER,\n port: process.env.ALGOD_PORT,\n token: process.env.ALGOD_TOKEN,\n }\n }\n\n /**\n * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).\n *\n * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n * @returns The Indexer client configuration\n * @throws Error if `process.env.INDEXER_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getIndexerConfigFromEnvironment()\n * ```\n */\n public static getIndexerConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.INDEXER_SERVER) {\n throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables')\n }\n\n return {\n server: process.env.INDEXER_SERVER,\n port: process.env.INDEXER_PORT,\n token: process.env.INDEXER_TOKEN,\n }\n }\n\n /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.\n *\n * @param network Which network to connect to - TestNet or MainNet\n * @param config Which algod config to return - Algod or Indexer\n * @returns The AlgoNode client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')\n * ```\n */\n public static getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig {\n return {\n server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,\n port: 443,\n }\n }\n\n /** Returns the Algorand configuration to point to the default LocalNet.\n *\n * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number\n * @returns The LocalNet client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getDefaultLocalNetConfig('algod')\n * ```\n */\n public static getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig {\n return {\n server: `http://localhost`,\n port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,\n token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n }\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls.\n *\n * @param config The config of the client\n * @returns The Algod client\n * @example AlgoNode (testnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClient(config: AlgoClientConfig): AlgodClient {\n const { token, server, port } = config\n return new AlgodClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Algod client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN\n * const algod = ClientManager.getAlgodClientFromEnvironment()\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClientFromEnvironment(): AlgodClient {\n return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment())\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls\n *\n * @param config The config of the client\n * @returns The Indexer client\n * @example AlgoNode (testnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClient(config: AlgoClientConfig): IndexerClient {\n const { token, server, port } = config\n return new IndexerClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Indexer client\n * @example\n *\n * ```typescript\n * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN\n * const indexer = ClientManager.getIndexerClientFromEnvironment()\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClientFromEnvironment(): IndexerClient {\n return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment())\n }\n\n /**\n * Returns a KMD SDK client.\n *\n * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.\n *\n * @param config The config for the client\n * @returns The KMD client\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * ```\n */\n public static getKmdClient(config: AlgoClientConfig): KmdClient {\n const { token, server, port } = config\n return new KmdClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The KMD client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN\n * const kmd = ClientManager.getKmdClientFromEnvironment()\n * ```\n */\n public static getKmdClientFromEnvironment(): KmdClient {\n // We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions\n // (e.g. same token and server as algod and port 4002 by default)\n return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' })\n }\n}\n\n/**\n * Interface to identify a typed client that can be used to interact with an application.\n */\nexport interface TypedAppClient<TClient> {\n new (params: Omit<AppClientParams, 'appSpec'>): TClient\n fromNetwork(params: Omit<AppClientParams, 'appId' | 'appSpec'>): Promise<TClient>\n fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<TClient>\n}\n\n/**\n * Interface to identify a typed factory that can be used to create and deploy an application.\n */\nexport interface TypedAppFactory<TClient> {\n new (params: Omit<AppFactoryParams, 'appSpec'>): TClient\n}\n"],"mappings":";;;;;;;;;;;AA8CA,IAAa,gBAAb,MAAa,cAAc;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;;;;;;;;;;;;;;CAsBR,YAAY,iBAA8C,gBAAiC;EACzF,MAAM,WACJ,WAAW,kBACP,kBACA;GACE,OAAO,cAAc,eAAe,gBAAgB,YAAY;GAChE,SAAS,gBAAgB,gBAAgB,cAAc,iBAAiB,gBAAgB,cAAc,GAAG;GACzG,KAAK,gBAAgB,YAAY,cAAc,aAAa,gBAAgB,UAAU,GAAG;GAC1F;AACP,OAAK,SAAS,SAAS;AACvB,OAAK,WAAW,SAAS;AACzB,OAAK,OAAO,SAAS;AACrB,OAAK,YAAY;;;;;;CAOnB,IAAW,QAAqB;AAC9B,SAAO,KAAK;;;;;;;CAQd,IAAW,UAAyB;AAClC,MAAI,CAAC,KAAK,SAAU,OAAM,IAAI,MAAM,+EAA+E;AACnH,SAAO,KAAK;;;;;;CAOd,IAAW,mBAA8C;AACvD,SAAO,KAAK;;;;;;;CAQd,IAAW,MAAiB;AAC1B,MAAI,CAAC,KAAK,KAAM,OAAM,IAAI,MAAM,uEAAuE;AACvG,SAA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;;;;;CAwBH,OAAc,eAAe,QAAuC;EAClE,MAAM,EAAE,OAAO,QAAQ,SAAS;AAChC,SAAO,IAAI,YAAY;GACrB,SAAS;GACT;GACA;GACA,QAAQ,OAAO;GAChB,CAAC;;;;;;;;;;;;;CAcJ,OAAc,gCAA6C;AACzD,SAAO,cAAc,eAAe,cAAc,+BAA+B,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAwBpF,OAAc,iBAAiB,QAAyC;EACtE,MAAM,EAAE,OAAO,QAAQ,SAAS;AAChC,SAAO,IAAI,cAAc;GACvB,SAAS;GACT;GACA;GACA,QAAQ,OAAO;GAChB,CAAC;;;;;;;;;;;;;;CAeJ,OAAc,kCAAiD;AAC7D,SAAO,cAAc,iBAAiB,cAAc,iCAAiC,CAAC;;;;;;;;;;;;;;CAexF,OAAc,aAAa,QAAqC;EAC9D,MAAM,EAAE,OAAO,QAAQ,SAAS;AAChC,SAAO,IAAI,UAAU;GACnB,SAAS;GACT;GACA;GACA,QAAQ,OAAO;GAChB,CAAC;;;;;;;;;;;;CAaJ,OAAc,8BAAyC;AAGrD,SAAO,cAAc,aAAa;GAAE,GAAG,cAAc,+BAA+B;GAAE,MAAM,SAAS,KAAK,YAAY;GAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"client-manager.mjs","names":[],"sources":["../../src/types/client-manager.ts"],"sourcesContent":["import { AlgodClient, SuggestedParams } from '@algorandfoundation/algokit-algod-client'\nimport { Expand } from '@algorandfoundation/algokit-common'\nimport { IndexerClient } from '@algorandfoundation/algokit-indexer-client'\nimport { KmdClient } from '@algorandfoundation/algokit-kmd-client'\nimport { Config } from '../config'\nimport { type AlgorandClient } from './algorand-client'\nimport { AppClient, AppClientParams, ResolveAppClientByCreatorAndName } from './app-client'\nimport { AppFactory, AppFactoryParams } from './app-factory'\nimport { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './dispenser-client'\nimport { AlgoClientConfig, AlgoConfig, NetworkDetails, genesisIdIsLocalNet } from './network-client'\n\n/** Clients from algosdk that interact with the official Algorand APIs */\nexport interface AlgoSdkClients {\n /** Algod client, see https://dev.algorand.co/reference/rest-apis/algod/ */\n algod: AlgodClient\n /** Optional indexer client, see https://dev.algorand.co/reference/rest-apis/indexer */\n indexer?: IndexerClient\n /** Optional KMD client, see https://dev.algorand.co/reference/rest-apis/kmd/ */\n kmd?: KmdClient\n}\n\n/** Params to get an app factory from `ClientManager`. */\nexport type ClientAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand'>>\n\n/** Params to get an app client by creator address and name from `ClientManager`. */\nexport type ClientResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand'>>\n\n/** Params to get an app client by ID from `ClientManager`. */\nexport type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand'>>\n\n/** Params to get an app client by network from `ClientManager`. */\nexport type ClientAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appId'>>\n\n/** Params to get a typed app client by creator address and name from `ClientManager`. */\nexport type ClientTypedAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by ID from `ClientManager`. */\nexport type ClientTypedAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by network from `ClientManager`. */\nexport type ClientTypedAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'>>\n\n/** Params to get a typed app factory from `ClientManager`. */\nexport type ClientTypedAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand' | 'appSpec'>>\n\n/** Exposes access to various API clients. */\nexport class ClientManager {\n private _algod: AlgodClient\n private _indexer?: IndexerClient\n private _kmd?: KmdClient\n private _algorand?: AlgorandClient\n\n /**\n * algosdk clients or config for interacting with the official Algorand APIs.\n * @param clientsOrConfig The clients or config to use\n * @example Algod client only\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient })\n * ```\n * @example All clients\n * ```typescript\n * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })\n * ```\n * @example Algod config only\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig })\n * ```\n * @example All client configs\n * ```typescript\n * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })\n * ```\n */\n constructor(clientsOrConfig: AlgoConfig | AlgoSdkClients, algorandClient?: AlgorandClient) {\n const _clients =\n 'algod' in clientsOrConfig\n ? clientsOrConfig\n : {\n algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),\n indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,\n kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,\n }\n this._algod = _clients.algod\n this._indexer = _clients.indexer\n this._kmd = _clients.kmd\n this._algorand = algorandClient\n }\n\n /**\n * Returns an Algod API client.\n * @returns The Algod client\n */\n public get algod(): AlgodClient {\n return this._algod\n }\n\n /**\n * Returns an Indexer API client or throws an error if it's not been provided.\n * @returns The Indexer client\n * @throws Error if no Indexer client is configured\n */\n public get indexer(): IndexerClient {\n if (!this._indexer) throw new Error('Attempt to use Indexer client in AlgoKit instance with no Indexer configured')\n return this._indexer\n }\n\n /**\n * Returns an Indexer API client or `undefined` if it's not been provided.\n * @returns The Indexer client or `undefined`\n */\n public get indexerIfPresent(): IndexerClient | undefined {\n return this._indexer\n }\n\n /**\n * Returns a KMD API client or throws an error if it's not been provided.\n * @returns The KMD client\n * @throws Error if no KMD client is configured\n */\n public get kmd(): KmdClient {\n if (!this._kmd) throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n return this._kmd\n }\n\n private _getNetworkPromise: Promise<SuggestedParams> | undefined\n /**\n * Get details about the current network.\n * @example Getting genesis ID\n * ```typescript\n * const network = await networkClient.network()\n * const genesisId = network.genesisId\n * ```\n * @returns The current network details\n */\n public async network(): Promise<NetworkDetails> {\n if (!this._getNetworkPromise) {\n this._getNetworkPromise = this._algod.suggestedParams()\n }\n\n const params = await this._getNetworkPromise\n return {\n isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisId ?? 'unknown'),\n isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisId ?? 'unknown'),\n isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisId ?? 'unknown'),\n genesisId: params.genesisId ?? 'unknown',\n genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',\n }\n }\n\n /**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n * @example\n * ```typescript\n * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')\n * ```\n */\n public static genesisIdIsLocalNet(genesisId: string) {\n return genesisIdIsLocalNet(genesisId)\n }\n\n /**\n * Returns true if the current network is LocalNet.\n * @returns True if the current network is LocalNet.\n * @example\n * ```typescript\n * const isLocalNet = await clientManager.isLocalNet()\n * ```\n */\n public async isLocalNet() {\n return (await this.network()).isLocalNet\n }\n\n /**\n * Returns true if the current network is TestNet.\n * @returns True if the current network is TestNet.\n * @example\n * ```typescript\n * const isTestNet = await clientManager.isTestNet()\n * ```\n */\n public async isTestNet() {\n return (await this.network()).isTestNet\n }\n\n /**\n * Returns true if the current network is MainNet.\n * @returns True if the current network is MainNet.\n * @example\n * ```typescript\n * const isMainNet = await clientManager.isMainNet()\n * ```\n */\n public async isMainNet() {\n return (await this.network()).isMainNet\n }\n\n /**\n * Returns a TestNet Dispenser API client.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenser(\n * {\n * authToken: 'your_auth_token',\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenser(params: TestNetDispenserApiClientParams) {\n return new TestNetDispenserApiClient(params)\n }\n\n /**\n * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.\n *\n * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n *\n * @param params An object containing parameters for the TestNetDispenserApiClient class.\n * @example\n * const client = clientManager.getTestNetDispenserFromEnvironment(\n * {\n * requestTimeout: 15,\n * }\n * )\n *\n * @returns An instance of the TestNetDispenserApiClient class.\n */\n public getTestNetDispenserFromEnvironment(params?: Omit<TestNetDispenserApiClientParams, 'authToken'>) {\n return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined)\n }\n\n /**\n * Returns a new `AppFactory` client\n * @param params The parameters to create the app factory\n * @example Basic example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\/}',\n * })\n * ```\n * @example Advanced example\n * ```typescript\n * const factory = clientManager.getAppFactory({\n * appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,\n * defaultSender: \"SENDERADDRESS\",\n * appName: \"OverriddenAppName\",\n * version: \"2.0.0\",\n * updatable: true,\n * deletable: false,\n * deployTimeParams: { ONE: 1, TWO: 'value' }\n * })\n * ```\n * @returns The `AppFactory` instance\n */\n public getAppFactory(params: ClientAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new AppFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * This method resolves the app ID by looking up the creator address and name\n * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByCreatorAndName({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by looking for app ID of named app by this creator\n * creatorAddress: 'CREATORADDRESS',\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientByCreatorAndName(params: ClientResolveAppClientByCreatorAndNameParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return AppClient.fromCreatorAndName({\n ...params,\n algorand: this._algorand,\n })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientById({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * appId: 12345n,\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public getAppClientById(params: ClientAppClientParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return new AppClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.\n * This method resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param params The parameters to create the app client\n * @example Basic\n * ```typescript\n * const appClient = clientManager.getAppClientByNetwork({\n * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n * // appId resolved by using ARC-56 spec to find app ID for current network\n * })\n * ```\n * @returns The `AppClient` instance\n */\n public async getAppClientByNetwork(params: ClientAppClientByNetworkParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n return AppClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by creator address and name.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by creator address and name\n * @example Use name in ARC-32 / ARC-56 app spec\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * defaultSender: alice,\n * })\n * ```\n * @example Specify name\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n * creatorAddress: \"CREATORADDRESS\",\n * name: \"contract-name\",\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public async getTypedAppClientByCreatorAndName<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientByCreatorAndNameParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromCreatorAndName({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolving the app by app ID.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by ID\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientById(MyContractClient, {\n * appId: 12345n,\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientById<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params: ClientTypedAppClientParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return new typedClient({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed client, resolves the app ID for the current network based on\n * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n *\n * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n * @param typedClient The typed client type to use\n * @param params The params to resolve the app by network\n * @example\n * ```typescript\n * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {\n * defaultSender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppClientByNetwork<TClient extends TypedAppClient<InstanceType<TClient>>>(\n typedClient: TClient,\n params?: ClientTypedAppClientByNetworkParams,\n ) {\n if (!this._algorand) {\n throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n }\n\n return typedClient.fromNetwork({ ...params, algorand: this._algorand })\n }\n\n /**\n * Returns a new typed app factory.\n * @param typedFactory The typed factory type to use\n * @param params The params to resolve the factory by\n * @example\n * ```typescript\n * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {\n * sender: alice,\n * })\n * ```\n * @returns The typed client instance\n */\n public getTypedAppFactory<TClient>(typedFactory: TypedAppFactory<TClient>, params?: ClientTypedAppFactoryParams) {\n if (!this._algorand) {\n throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n }\n\n return new typedFactory({ ...params, algorand: this._algorand })\n }\n\n /**\n * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)\n *\n * 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`.\n *\n * 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`.\n *\n * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @example\n * ```typescript\n * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()\n * ```\n * @returns The config for algod, indexer and kmd\n */\n public static getConfigFromEnvironmentOrLocalNet(): AlgoConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead')\n }\n const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER\n ? [\n ClientManager.getAlgodConfigFromEnvironment(),\n process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,\n !process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')\n ? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }\n : undefined,\n ]\n : [\n ClientManager.getDefaultLocalNetConfig('algod'),\n ClientManager.getDefaultLocalNetConfig('indexer'),\n ClientManager.getDefaultLocalNetConfig('kmd'),\n ]\n\n return {\n algodConfig,\n indexerConfig,\n kmdConfig,\n }\n }\n\n /**\n * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)\n *\n * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n * @returns The Algod client configuration\n * @throws Error if `process.env.ALGOD_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getAlgodConfigFromEnvironment()\n * ```\n */\n public static getAlgodConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.ALGOD_SERVER) {\n throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables')\n }\n\n return {\n server: process.env.ALGOD_SERVER,\n port: process.env.ALGOD_PORT,\n token: process.env.ALGOD_TOKEN,\n }\n }\n\n /**\n * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).\n *\n * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n * @returns The Indexer client configuration\n * @throws Error if `process.env.INDEXER_SERVER` is not defined\n * @example\n * ```typescript\n * const config = ClientManager.getIndexerConfigFromEnvironment()\n * ```\n */\n public static getIndexerConfigFromEnvironment(): AlgoClientConfig {\n if (!process || !process.env) {\n throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead')\n }\n\n if (!process.env.INDEXER_SERVER) {\n throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables')\n }\n\n return {\n server: process.env.INDEXER_SERVER,\n port: process.env.INDEXER_PORT,\n token: process.env.INDEXER_TOKEN,\n }\n }\n\n /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.\n *\n * @param network Which network to connect to - TestNet or MainNet\n * @param config Which algod config to return - Algod or Indexer\n * @returns The AlgoNode client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')\n * ```\n */\n public static getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig {\n return {\n server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,\n port: 443,\n }\n }\n\n /** Returns the Algorand configuration to point to the default LocalNet.\n *\n * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number\n * @returns The LocalNet client configuration\n * @example\n * ```typescript\n * const config = ClientManager.getDefaultLocalNetConfig('algod')\n * ```\n */\n public static getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig {\n return {\n server: `http://localhost`,\n port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,\n token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n }\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls.\n *\n * @param config The config of the client\n * @returns The Algod client\n * @example AlgoNode (testnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))\n * await algod.healthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet)\n * ```typescript\n * const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClient(config: AlgoClientConfig): AlgodClient {\n const { token, server, port } = config\n return new AlgodClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Algod client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN\n * const algod = ClientManager.getAlgodClientFromEnvironment()\n * await algod.healthCheck().do()\n * ```\n */\n public static getAlgodClientFromEnvironment(): AlgodClient {\n return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment())\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls\n *\n * @param config The config of the client\n * @returns The Indexer client\n * @example AlgoNode (testnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example AlgoNode (mainnet)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))\n * await indexer.makeHealthCheck().do()\n * ```\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClient(config: AlgoClientConfig): IndexerClient {\n const { token, server, port } = config\n return new IndexerClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The Indexer client\n * @example\n *\n * ```typescript\n * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN\n * const indexer = ClientManager.getIndexerClientFromEnvironment()\n * await indexer.makeHealthCheck().do()\n * ```\n */\n public static getIndexerClientFromEnvironment(): IndexerClient {\n return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment())\n }\n\n /**\n * Returns a KMD SDK client.\n *\n * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.\n *\n * @param config The config for the client\n * @returns The KMD client\n * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n * ```typescript\n * const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n * ```\n */\n public static getKmdClient(config: AlgoClientConfig): KmdClient {\n const { token, server, port } = config\n return new KmdClient({\n baseUrl: server,\n port,\n token,\n logger: Config.logger,\n })\n }\n\n /**\n * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n *\n * @returns The KMD client\n * @example\n * ```typescript\n * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN\n * const kmd = ClientManager.getKmdClientFromEnvironment()\n * ```\n */\n public static getKmdClientFromEnvironment(): KmdClient {\n // We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions\n // (e.g. same token and server as algod and port 4002 by default)\n return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' })\n }\n}\n\n/**\n * Interface to identify a typed client that can be used to interact with an application.\n */\nexport interface TypedAppClient<TClient> {\n new (params: Omit<AppClientParams, 'appSpec'>): TClient\n fromNetwork(params: Omit<AppClientParams, 'appId' | 'appSpec'>): Promise<TClient>\n fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<TClient>\n}\n\n/**\n * Interface to identify a typed factory that can be used to create and deploy an application.\n */\nexport interface TypedAppFactory<TClient> {\n new (params: Omit<AppFactoryParams, 'appSpec'>): TClient\n}\n"],"mappings":";;;;;;;;;;;AA8CA,IAAa,gBAAb,MAAa,cAAc;CACzB,AAAQ;CACR,AAAQ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AAI,UAAU;GACnB,SAAS;GACT;GACA;GACA,QAAQ,OAAO;GAChB,CAAC;;;;;;;;;;;;CAaJ,OAAc,8BAAyC;AAGrD,SAAO,cAAc,aAAa;GAAE,GAAG,cAAc,+BAA+B;GAAE,MAAM,SAAS,KAAK,YAAY;GAAQ,CAAC"}
|
package/types/composer.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReadableAddress } from "../packages/common/src/address.js";
|
|
2
|
+
import { Expand } from "../packages/common/src/expand.js";
|
|
2
3
|
import { ABIMethod } from "../packages/abi/src/abi-method.js";
|
|
3
4
|
import { Transaction } from "../packages/transact/src/transactions/transaction.js";
|
|
4
5
|
import { SignedTransaction } from "../packages/transact/src/transactions/signed-transaction.js";
|
|
@@ -9,7 +10,6 @@ import { SuggestedParams } from "../packages/algod_client/src/models/suggested-p
|
|
|
9
10
|
import { AlgodClient } from "../packages/algod_client/src/client.js";
|
|
10
11
|
import { AlgoAmount } from "./amount.js";
|
|
11
12
|
import { AppManager } from "./app-manager.js";
|
|
12
|
-
import { Expand } from "./expand.js";
|
|
13
13
|
import { CommonTransactionParams } from "../transactions/common.js";
|
|
14
14
|
import { AppCallParams, AppCreateParams, AppDeleteParams, AppMethodCallParams, AppUpdateParams, CommonAppCallParams } from "../transactions/app-call.js";
|
|
15
15
|
import { AssetOptInParams, AssetOptOutParams, AssetTransferParams } from "../transactions/asset-transfer.js";
|
package/types/composer.js
CHANGED
|
@@ -1462,7 +1462,7 @@ var TransactionComposer = class TransactionComposer {
|
|
|
1462
1462
|
let transactionsWithSigner;
|
|
1463
1463
|
if (!this.transactionsWithSigners) {
|
|
1464
1464
|
const builtTransactions = await this.buildTransactions();
|
|
1465
|
-
transactionsWithSigner = (builtTransactions.transactions.length >
|
|
1465
|
+
transactionsWithSigner = (builtTransactions.transactions.length > 1 ? require_transaction.groupTransactions(builtTransactions.transactions) : builtTransactions.transactions).map((txn, index) => ({
|
|
1466
1466
|
txn,
|
|
1467
1467
|
signer: skipSignatures ? require_signer.makeEmptyTransactionSigner() : builtTransactions.signers.get(index) ?? require_signer.makeEmptyTransactionSigner()
|
|
1468
1468
|
}));
|
|
@@ -1491,10 +1491,10 @@ var TransactionComposer = class TransactionComposer {
|
|
|
1491
1491
|
if (simulateResult?.failureMessage && !resultOnFailure) {
|
|
1492
1492
|
const errorMessage = `Transaction failed at transaction(s) ${simulateResult.failedAt?.join(", ") || "unknown"} in the group. ${simulateResult.failureMessage}`;
|
|
1493
1493
|
const error = new Error(errorMessage);
|
|
1494
|
-
if (require_config.Config.debug) await require_config.Config.events.emitAsync(require_lifecycle_events.EventType.TxnGroupSimulated, {
|
|
1494
|
+
if (require_config.Config.debug) await require_config.Config.events.emitAsync(require_lifecycle_events.EventType.TxnGroupSimulated, { simulateResponse });
|
|
1495
1495
|
throw await this.transformError(error);
|
|
1496
1496
|
}
|
|
1497
|
-
if (require_config.Config.debug && require_config.Config.traceAll) await require_config.Config.events.emitAsync(require_lifecycle_events.EventType.TxnGroupSimulated, {
|
|
1497
|
+
if (require_config.Config.debug && require_config.Config.traceAll) await require_config.Config.events.emitAsync(require_lifecycle_events.EventType.TxnGroupSimulated, { simulateResponse });
|
|
1498
1498
|
const abiReturns = this.parseAbiReturnValues(simulateResult.txnResults.map((t) => t.txnResult));
|
|
1499
1499
|
return {
|
|
1500
1500
|
confirmations: simulateResult.txnResults.map((t) => t.txnResult),
|