@algorandfoundation/algokit-utils 9.2.0 → 9.2.1-beta.2

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.
Files changed (340) hide show
  1. package/_virtual/_rolldown/runtime.js +33 -0
  2. package/_virtual/_rolldown/runtime.mjs +13 -0
  3. package/account/account.d.ts +25 -30
  4. package/account/account.js +151 -146
  5. package/account/account.js.map +1 -1
  6. package/account/account.mjs +149 -144
  7. package/account/account.mjs.map +1 -1
  8. package/account/get-account-config-from-environment.d.ts +7 -2
  9. package/account/get-account-config-from-environment.js +19 -21
  10. package/account/get-account-config-from-environment.js.map +1 -1
  11. package/account/get-account-config-from-environment.mjs +19 -19
  12. package/account/get-account-config-from-environment.mjs.map +1 -1
  13. package/account/get-account.d.ts +14 -12
  14. package/account/get-account.js +56 -59
  15. package/account/get-account.js.map +1 -1
  16. package/account/get-account.mjs +56 -57
  17. package/account/get-account.mjs.map +1 -1
  18. package/account/get-dispenser-account.d.ts +9 -5
  19. package/account/get-dispenser-account.js +20 -18
  20. package/account/get-dispenser-account.js.map +1 -1
  21. package/account/get-dispenser-account.mjs +20 -16
  22. package/account/get-dispenser-account.mjs.map +1 -1
  23. package/account/mnemonic-account.d.ts +7 -3
  24. package/account/mnemonic-account.js +17 -17
  25. package/account/mnemonic-account.js.map +1 -1
  26. package/account/mnemonic-account.mjs +15 -15
  27. package/account/mnemonic-account.mjs.map +1 -1
  28. package/amount.d.ts +40 -35
  29. package/amount.js +33 -34
  30. package/amount.js.map +1 -1
  31. package/amount.mjs +33 -32
  32. package/amount.mjs.map +1 -1
  33. package/app-client.d.ts +10 -6
  34. package/app-client.js +91 -86
  35. package/app-client.js.map +1 -1
  36. package/app-client.mjs +91 -84
  37. package/app-client.mjs.map +1 -1
  38. package/app-deploy.d.ts +26 -24
  39. package/app-deploy.js +235 -253
  40. package/app-deploy.js.map +1 -1
  41. package/app-deploy.mjs +233 -251
  42. package/app-deploy.mjs.map +1 -1
  43. package/app.d.ts +45 -46
  44. package/app.js +253 -271
  45. package/app.js.map +1 -1
  46. package/app.mjs +249 -267
  47. package/app.mjs.map +1 -1
  48. package/asset.d.ts +16 -12
  49. package/asset.js +116 -122
  50. package/asset.js.map +1 -1
  51. package/asset.mjs +116 -120
  52. package/asset.mjs.map +1 -1
  53. package/config.d.ts +7 -2
  54. package/config.js +5 -7
  55. package/config.js.map +1 -1
  56. package/config.mjs +5 -4
  57. package/config.mjs.map +1 -1
  58. package/debugging/debugging.d.ts +5 -1
  59. package/debugging/debugging.js +11 -11
  60. package/debugging/debugging.js.map +1 -1
  61. package/debugging/debugging.mjs +11 -9
  62. package/debugging/debugging.mjs.map +1 -1
  63. package/dispenser-client.d.ts +7 -2
  64. package/dispenser-client.js +23 -24
  65. package/dispenser-client.js.map +1 -1
  66. package/dispenser-client.mjs +23 -22
  67. package/dispenser-client.mjs.map +1 -1
  68. package/index.d.ts +27 -18
  69. package/index.js +140 -143
  70. package/index.mjs +27 -29
  71. package/indexer-lookup.d.ts +18 -11
  72. package/indexer-lookup.js +112 -120
  73. package/indexer-lookup.js.map +1 -1
  74. package/indexer-lookup.mjs +105 -118
  75. package/indexer-lookup.mjs.map +1 -1
  76. package/localnet/get-kmd-wallet-account.d.ts +9 -7
  77. package/localnet/get-kmd-wallet-account.js +28 -26
  78. package/localnet/get-kmd-wallet-account.js.map +1 -1
  79. package/localnet/get-kmd-wallet-account.mjs +28 -24
  80. package/localnet/get-kmd-wallet-account.mjs.map +1 -1
  81. package/localnet/get-localnet-dispenser-account.d.ts +7 -5
  82. package/localnet/get-localnet-dispenser-account.js +17 -15
  83. package/localnet/get-localnet-dispenser-account.js.map +1 -1
  84. package/localnet/get-localnet-dispenser-account.mjs +17 -13
  85. package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
  86. package/localnet/get-or-create-kmd-wallet-account.d.ts +10 -8
  87. package/localnet/get-or-create-kmd-wallet-account.js +28 -26
  88. package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
  89. package/localnet/get-or-create-kmd-wallet-account.mjs +28 -24
  90. package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
  91. package/localnet/is-localnet.d.ts +7 -3
  92. package/localnet/is-localnet.js +9 -10
  93. package/localnet/is-localnet.js.map +1 -1
  94. package/localnet/is-localnet.mjs +9 -8
  95. package/localnet/is-localnet.mjs.map +1 -1
  96. package/network-client.d.ts +17 -15
  97. package/network-client.js +115 -116
  98. package/network-client.js.map +1 -1
  99. package/network-client.mjs +115 -114
  100. package/network-client.mjs.map +1 -1
  101. package/package.json +12 -3
  102. package/testing/account.d.ts +11 -9
  103. package/testing/account.js +31 -33
  104. package/testing/account.js.map +1 -1
  105. package/testing/account.mjs +29 -31
  106. package/testing/account.mjs.map +1 -1
  107. package/testing/fixtures/algokit-log-capture-fixture.d.ts +7 -2
  108. package/testing/fixtures/algokit-log-capture-fixture.js +36 -41
  109. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  110. package/testing/fixtures/algokit-log-capture-fixture.mjs +36 -39
  111. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  112. package/testing/fixtures/algorand-fixture.d.ts +9 -4
  113. package/testing/fixtures/algorand-fixture.js +67 -62
  114. package/testing/fixtures/algorand-fixture.js.map +1 -1
  115. package/testing/fixtures/algorand-fixture.mjs +66 -59
  116. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  117. package/testing/index.d.ts +7 -5
  118. package/testing/index.js +13 -18
  119. package/testing/index.mjs +7 -7
  120. package/testing/indexer.d.ts +5 -1
  121. package/testing/indexer.js +28 -37
  122. package/testing/indexer.js.map +1 -1
  123. package/testing/indexer.mjs +28 -35
  124. package/testing/indexer.mjs.map +1 -1
  125. package/testing/test-logger.d.ts +41 -36
  126. package/testing/test-logger.js +71 -76
  127. package/testing/test-logger.js.map +1 -1
  128. package/testing/test-logger.mjs +71 -74
  129. package/testing/test-logger.mjs.map +1 -1
  130. package/testing/transaction-logger.d.ts +30 -27
  131. package/testing/transaction-logger.js +77 -93
  132. package/testing/transaction-logger.js.map +1 -1
  133. package/testing/transaction-logger.mjs +74 -90
  134. package/testing/transaction-logger.mjs.map +1 -1
  135. package/transaction/legacy-bridge.js +100 -111
  136. package/transaction/legacy-bridge.js.map +1 -1
  137. package/transaction/legacy-bridge.mjs +97 -108
  138. package/transaction/legacy-bridge.mjs.map +1 -1
  139. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +7 -5
  140. package/transaction/perform-atomic-transaction-composer-simulate.js +31 -36
  141. package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
  142. package/transaction/perform-atomic-transaction-composer-simulate.mjs +28 -33
  143. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
  144. package/transaction/transaction.d.ts +34 -35
  145. package/transaction/transaction.js +716 -914
  146. package/transaction/transaction.js.map +1 -1
  147. package/transaction/transaction.mjs +713 -911
  148. package/transaction/transaction.mjs.map +1 -1
  149. package/transfer/transfer-algos.d.ts +9 -5
  150. package/transfer/transfer-algos.js +26 -27
  151. package/transfer/transfer-algos.js.map +1 -1
  152. package/transfer/transfer-algos.mjs +26 -25
  153. package/transfer/transfer-algos.mjs.map +1 -1
  154. package/transfer/transfer.d.ts +11 -8
  155. package/transfer/transfer.js +94 -100
  156. package/transfer/transfer.js.map +1 -1
  157. package/transfer/transfer.mjs +94 -98
  158. package/transfer/transfer.mjs.map +1 -1
  159. package/types/account-manager.d.ts +432 -429
  160. package/types/account-manager.js +591 -602
  161. package/types/account-manager.js.map +1 -1
  162. package/types/account-manager.mjs +587 -599
  163. package/types/account-manager.mjs.map +1 -1
  164. package/types/account.d.ts +192 -202
  165. package/types/account.js +91 -88
  166. package/types/account.js.map +1 -1
  167. package/types/account.mjs +88 -86
  168. package/types/account.mjs.map +1 -1
  169. package/types/algo-http-client-with-retry.d.ts +15 -10
  170. package/types/algo-http-client-with-retry.js +70 -92
  171. package/types/algo-http-client-with-retry.js.map +1 -1
  172. package/types/algo-http-client-with-retry.mjs +69 -90
  173. package/types/algo-http-client-with-retry.mjs.map +1 -1
  174. package/types/algorand-client-transaction-creator.d.ts +778 -771
  175. package/types/algorand-client-transaction-creator.js +733 -732
  176. package/types/algorand-client-transaction-creator.js.map +1 -1
  177. package/types/algorand-client-transaction-creator.mjs +732 -730
  178. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  179. package/types/algorand-client-transaction-sender.d.ts +1090 -1360
  180. package/types/algorand-client-transaction-sender.js +930 -961
  181. package/types/algorand-client-transaction-sender.js.map +1 -1
  182. package/types/algorand-client-transaction-sender.mjs +927 -959
  183. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  184. package/types/algorand-client.d.ts +239 -236
  185. package/types/algorand-client.js +322 -320
  186. package/types/algorand-client.js.map +1 -1
  187. package/types/algorand-client.mjs +321 -318
  188. package/types/algorand-client.mjs.map +1 -1
  189. package/types/amount.d.ts +47 -43
  190. package/types/amount.js +66 -70
  191. package/types/amount.js.map +1 -1
  192. package/types/amount.mjs +63 -68
  193. package/types/amount.mjs.map +1 -1
  194. package/types/app-arc56.d.ts +235 -272
  195. package/types/app-arc56.js +124 -170
  196. package/types/app-arc56.js.map +1 -1
  197. package/types/app-arc56.mjs +121 -168
  198. package/types/app-arc56.mjs.map +1 -1
  199. package/types/app-client.d.ts +1128 -2009
  200. package/types/app-client.js +1633 -1791
  201. package/types/app-client.js.map +1 -1
  202. package/types/app-client.mjs +1624 -1783
  203. package/types/app-client.mjs.map +1 -1
  204. package/types/app-deployer.d.ts +139 -141
  205. package/types/app-deployer.js +344 -384
  206. package/types/app-deployer.js.map +1 -1
  207. package/types/app-deployer.mjs +341 -382
  208. package/types/app-deployer.mjs.map +1 -1
  209. package/types/app-factory.d.ts +762 -932
  210. package/types/app-factory.js +496 -488
  211. package/types/app-factory.js.map +1 -1
  212. package/types/app-factory.mjs +491 -484
  213. package/types/app-factory.mjs.map +1 -1
  214. package/types/app-manager.d.ts +304 -310
  215. package/types/app-manager.js +422 -475
  216. package/types/app-manager.js.map +1 -1
  217. package/types/app-manager.mjs +419 -473
  218. package/types/app-manager.mjs.map +1 -1
  219. package/types/app-spec.d.ts +118 -117
  220. package/types/app-spec.js +125 -135
  221. package/types/app-spec.js.map +1 -1
  222. package/types/app-spec.mjs +121 -132
  223. package/types/app-spec.mjs.map +1 -1
  224. package/types/app.d.ts +229 -241
  225. package/types/app.js +36 -28
  226. package/types/app.js.map +1 -1
  227. package/types/app.mjs +33 -26
  228. package/types/app.mjs.map +1 -1
  229. package/types/asset-manager.d.ts +204 -199
  230. package/types/asset-manager.js +165 -174
  231. package/types/asset-manager.js.map +1 -1
  232. package/types/asset-manager.mjs +164 -172
  233. package/types/asset-manager.mjs.map +1 -1
  234. package/types/asset.d.ts +95 -91
  235. package/types/asset.js +0 -3
  236. package/types/asset.mjs +0 -2
  237. package/types/async-event-emitter.d.ts +18 -13
  238. package/types/async-event-emitter.js +37 -49
  239. package/types/async-event-emitter.js.map +1 -1
  240. package/types/async-event-emitter.mjs +36 -47
  241. package/types/async-event-emitter.mjs.map +1 -1
  242. package/types/client-manager.d.ts +453 -451
  243. package/types/client-manager.js +602 -598
  244. package/types/client-manager.js.map +1 -1
  245. package/types/client-manager.mjs +597 -594
  246. package/types/client-manager.mjs.map +1 -1
  247. package/types/composer.d.ts +1211 -1258
  248. package/types/composer.js +1436 -1498
  249. package/types/composer.js.map +1 -1
  250. package/types/composer.mjs +1430 -1493
  251. package/types/composer.mjs.map +1 -1
  252. package/types/config.d.ts +53 -48
  253. package/types/config.js +78 -77
  254. package/types/config.js.map +1 -1
  255. package/types/config.mjs +77 -75
  256. package/types/config.mjs.map +1 -1
  257. package/types/debugging.d.ts +25 -23
  258. package/types/debugging.js +9 -11
  259. package/types/debugging.js.map +1 -1
  260. package/types/debugging.mjs +8 -9
  261. package/types/debugging.mjs.map +1 -1
  262. package/types/dispenser-client.d.ts +57 -52
  263. package/types/dispenser-client.js +120 -141
  264. package/types/dispenser-client.js.map +1 -1
  265. package/types/dispenser-client.mjs +119 -139
  266. package/types/dispenser-client.mjs.map +1 -1
  267. package/types/expand.d.ts +5 -3
  268. package/types/expand.js +0 -3
  269. package/types/expand.mjs +0 -2
  270. package/types/indexer.d.ts +104 -100
  271. package/types/indexer.js +36 -31
  272. package/types/indexer.js.map +1 -1
  273. package/types/indexer.mjs +32 -30
  274. package/types/indexer.mjs.map +1 -1
  275. package/types/instance-of.d.ts +5 -3
  276. package/types/instance-of.js +0 -3
  277. package/types/instance-of.mjs +0 -2
  278. package/types/kmd-account-manager.d.ts +75 -70
  279. package/types/kmd-account-manager.js +150 -184
  280. package/types/kmd-account-manager.js.map +1 -1
  281. package/types/kmd-account-manager.mjs +147 -182
  282. package/types/kmd-account-manager.mjs.map +1 -1
  283. package/types/lifecycle-events.d.ts +13 -8
  284. package/types/lifecycle-events.js +10 -7
  285. package/types/lifecycle-events.js.map +1 -1
  286. package/types/lifecycle-events.mjs +9 -7
  287. package/types/lifecycle-events.mjs.map +1 -1
  288. package/types/logging.d.ts +15 -11
  289. package/types/logging.js +30 -31
  290. package/types/logging.js.map +1 -1
  291. package/types/logging.mjs +29 -29
  292. package/types/logging.mjs.map +1 -1
  293. package/types/logic-error.d.ts +33 -29
  294. package/types/logic-error.js +50 -49
  295. package/types/logic-error.js.map +1 -1
  296. package/types/logic-error.mjs +49 -47
  297. package/types/logic-error.mjs.map +1 -1
  298. package/types/network-client.d.ts +32 -27
  299. package/types/network-client.js +10 -9
  300. package/types/network-client.js.map +1 -1
  301. package/types/network-client.mjs +9 -7
  302. package/types/network-client.mjs.map +1 -1
  303. package/types/testing.d.ts +131 -132
  304. package/types/testing.js +0 -3
  305. package/types/testing.mjs +0 -2
  306. package/types/transaction.d.ts +110 -110
  307. package/types/transaction.js +0 -3
  308. package/types/transaction.mjs +0 -2
  309. package/types/transfer.d.ts +70 -66
  310. package/types/transfer.js +0 -3
  311. package/types/transfer.mjs +0 -2
  312. package/util.js +73 -118
  313. package/util.js.map +1 -1
  314. package/util.mjs +73 -116
  315. package/util.mjs.map +1 -1
  316. package/account/index.d.ts +0 -5
  317. package/debugging/index.d.ts +0 -1
  318. package/index.js.map +0 -1
  319. package/index.mjs.map +0 -1
  320. package/localnet/index.d.ts +0 -4
  321. package/testing/_asset.d.ts +0 -3
  322. package/testing/fixtures/index.d.ts +0 -2
  323. package/testing/index.js.map +0 -1
  324. package/testing/index.mjs.map +0 -1
  325. package/transaction/index.d.ts +0 -2
  326. package/transaction/legacy-bridge.d.ts +0 -35
  327. package/transfer/index.d.ts +0 -2
  328. package/types/asset.js.map +0 -1
  329. package/types/asset.mjs.map +0 -1
  330. package/types/expand.js.map +0 -1
  331. package/types/expand.mjs.map +0 -1
  332. package/types/instance-of.js.map +0 -1
  333. package/types/instance-of.mjs.map +0 -1
  334. package/types/testing.js.map +0 -1
  335. package/types/testing.mjs.map +0 -1
  336. package/types/transaction.js.map +0 -1
  337. package/types/transaction.mjs.map +0 -1
  338. package/types/transfer.js.map +0 -1
  339. package/types/transfer.mjs.map +0 -1
  340. package/util.d.ts +0 -48
@@ -1,598 +1,601 @@
1
- import algosdk from 'algosdk';
2
- import { AlgoHttpClientWithRetry } from './algo-http-client-with-retry.mjs';
3
- import { AppClient } from './app-client.mjs';
4
- import { AppFactory } from './app-factory.mjs';
5
- import { TestNetDispenserApiClient } from './dispenser-client.mjs';
6
- import { genesisIdIsLocalNet } from './network-client.mjs';
7
-
1
+ import { genesisIdIsLocalNet } from "./network-client.mjs";
2
+ import { AlgoHttpClientWithRetry } from "./algo-http-client-with-retry.mjs";
3
+ import { AppClient } from "./app-client.mjs";
4
+ import { AppFactory } from "./app-factory.mjs";
5
+ import { TestNetDispenserApiClient } from "./dispenser-client.mjs";
6
+ import algosdk from "algosdk";
7
+ //#region src/types/client-manager.ts
8
8
  var Kmd = algosdk.Kmd;
9
9
  var Indexer = algosdk.Indexer;
10
10
  /** Exposes access to various API clients. */
11
- class ClientManager {
12
- /**
13
- * algosdk clients or config for interacting with the official Algorand APIs.
14
- * @param clientsOrConfig The clients or config to use
15
- * @example Algod client only
16
- * ```typescript
17
- * const clientManager = new ClientManager({ algod: algodClient })
18
- * ```
19
- * @example All clients
20
- * ```typescript
21
- * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })
22
- * ```
23
- * @example Algod config only
24
- * ```typescript
25
- * const clientManager = new ClientManager({ algodConfig })
26
- * ```
27
- * @example All client configs
28
- * ```typescript
29
- * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })
30
- * ```
31
- */
32
- constructor(clientsOrConfig, algorandClient) {
33
- const _clients = 'algod' in clientsOrConfig
34
- ? clientsOrConfig
35
- : {
36
- algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),
37
- indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,
38
- kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,
39
- };
40
- this._algod = _clients.algod;
41
- this._indexer = _clients.indexer;
42
- this._kmd = _clients.kmd;
43
- this._algorand = algorandClient;
44
- }
45
- /**
46
- * Returns an algosdk Algod API client.
47
- * @returns The Algod client
48
- */
49
- get algod() {
50
- return this._algod;
51
- }
52
- /**
53
- * Returns an algosdk Indexer API client or throws an error if it's not been provided.
54
- * @returns The Indexer client
55
- * @throws Error if no Indexer client is configured
56
- */
57
- get indexer() {
58
- if (!this._indexer)
59
- throw new Error('Attempt to use Indexer client in AlgoKit instance with no Indexer configured');
60
- return this._indexer;
61
- }
62
- /**
63
- * Returns an algosdk Indexer API client or `undefined` if it's not been provided.
64
- * @returns The Indexer client or `undefined`
65
- */
66
- get indexerIfPresent() {
67
- return this._indexer;
68
- }
69
- /**
70
- * Returns an algosdk KMD API client or throws an error if it's not been provided.
71
- * @returns The KMD client
72
- * @throws Error if no KMD client is configured
73
- */
74
- get kmd() {
75
- if (!this._kmd)
76
- throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured');
77
- return this._kmd;
78
- }
79
- /**
80
- * Get details about the current network.
81
- * @example Getting genesis ID
82
- * ```typescript
83
- * const network = await networkClient.network()
84
- * const genesisId = network.genesisId
85
- * ```
86
- * @returns The current network details
87
- */
88
- async network() {
89
- if (!this._getNetworkPromise) {
90
- this._getNetworkPromise = this._algod.getTransactionParams().do();
91
- }
92
- const params = await this._getNetworkPromise;
93
- return {
94
- isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisID ?? 'unknown'),
95
- isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisID ?? 'unknown'),
96
- isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisID ?? 'unknown'),
97
- genesisId: params.genesisID ?? 'unknown',
98
- genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',
99
- };
100
- }
101
- /**
102
- * Returns true if the given network genesisId is associated with a LocalNet network.
103
- * @param genesisId The network genesis ID
104
- * @returns Whether the given genesis ID is associated with a LocalNet network
105
- * @example
106
- * ```typescript
107
- * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')
108
- * ```
109
- */
110
- static genesisIdIsLocalNet(genesisId) {
111
- return genesisIdIsLocalNet(genesisId);
112
- }
113
- /**
114
- * Returns true if the current network is LocalNet.
115
- * @returns True if the current network is LocalNet.
116
- * @example
117
- * ```typescript
118
- * const isLocalNet = await clientManager.isLocalNet()
119
- * ```
120
- */
121
- async isLocalNet() {
122
- return (await this.network()).isLocalNet;
123
- }
124
- /**
125
- * Returns true if the current network is TestNet.
126
- * @returns True if the current network is TestNet.
127
- * @example
128
- * ```typescript
129
- * const isTestNet = await clientManager.isTestNet()
130
- * ```
131
- */
132
- async isTestNet() {
133
- return (await this.network()).isTestNet;
134
- }
135
- /**
136
- * Returns true if the current network is MainNet.
137
- * @returns True if the current network is MainNet.
138
- * @example
139
- * ```typescript
140
- * const isMainNet = await clientManager.isMainNet()
141
- * ```
142
- */
143
- async isMainNet() {
144
- return (await this.network()).isMainNet;
145
- }
146
- /**
147
- * Returns a TestNet Dispenser API client.
148
- *
149
- * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.
150
- *
151
- * @param params An object containing parameters for the TestNetDispenserApiClient class.
152
- * @example
153
- * const client = clientManager.getTestNetDispenser(
154
- * {
155
- * authToken: 'your_auth_token',
156
- * requestTimeout: 15,
157
- * }
158
- * )
159
- *
160
- * @returns An instance of the TestNetDispenserApiClient class.
161
- */
162
- getTestNetDispenser(params) {
163
- return new TestNetDispenserApiClient(params);
164
- }
165
- /**
166
- * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.
167
- *
168
- * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.
169
- *
170
- * @param params An object containing parameters for the TestNetDispenserApiClient class.
171
- * @example
172
- * const client = clientManager.getTestNetDispenserFromEnvironment(
173
- * {
174
- * requestTimeout: 15,
175
- * }
176
- * )
177
- *
178
- * @returns An instance of the TestNetDispenserApiClient class.
179
- */
180
- getTestNetDispenserFromEnvironment(params) {
181
- return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined);
182
- }
183
- /**
184
- * Returns a new `AppFactory` client
185
- * @param params The parameters to create the app factory
186
- * @example Basic example
187
- * ```typescript
188
- * const factory = clientManager.getAppFactory({
189
- * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\/}',
190
- * })
191
- * ```
192
- * @example Advanced example
193
- * ```typescript
194
- * const factory = clientManager.getAppFactory({
195
- * appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,
196
- * defaultSender: "SENDERADDRESS",
197
- * appName: "OverriddenAppName",
198
- * version: "2.0.0",
199
- * updatable: true,
200
- * deletable: false,
201
- * deployTimeParams: { ONE: 1, TWO: 'value' }
202
- * })
203
- * ```
204
- * @returns The `AppFactory` instance
205
- */
206
- getAppFactory(params) {
207
- if (!this._algorand) {
208
- throw new Error('Attempt to get app factory from a ClientManager without an Algorand client');
209
- }
210
- return new AppFactory({ ...params, algorand: this._algorand });
211
- }
212
- /**
213
- * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.
214
- * This method resolves the app ID by looking up the creator address and name
215
- * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
216
- * @param params The parameters to create the app client
217
- * @example Basic
218
- * ```typescript
219
- * const appClient = clientManager.getAppClientByCreatorAndName({
220
- * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\}',
221
- * // appId resolved by looking for app ID of named app by this creator
222
- * creatorAddress: 'CREATORADDRESS',
223
- * })
224
- * ```
225
- * @returns The `AppClient` instance
226
- */
227
- getAppClientByCreatorAndName(params) {
228
- if (!this._algorand) {
229
- throw new Error('Attempt to get app client from a ClientManager without an Algorand client');
230
- }
231
- return AppClient.fromCreatorAndName({
232
- ...params,
233
- algorand: this._algorand,
234
- });
235
- }
236
- /**
237
- * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.
238
- * @param params The parameters to create the app client
239
- * @example Basic
240
- * ```typescript
241
- * const appClient = clientManager.getAppClientById({
242
- * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\}',
243
- * appId: 12345n,
244
- * })
245
- * ```
246
- * @returns The `AppClient` instance
247
- */
248
- getAppClientById(params) {
249
- if (!this._algorand) {
250
- throw new Error('Attempt to get app client from a ClientManager without an Algorand client');
251
- }
252
- return new AppClient({ ...params, algorand: this._algorand });
253
- }
254
- /**
255
- * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.
256
- * This method resolves the app ID for the current network based on
257
- * pre-determined network-specific app IDs specified in the ARC-56 app spec.
258
- *
259
- * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
260
- * @param params The parameters to create the app client
261
- * @example Basic
262
- * ```typescript
263
- * const appClient = clientManager.getAppClientByNetwork({
264
- * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\}',
265
- * // appId resolved by using ARC-56 spec to find app ID for current network
266
- * })
267
- * ```
268
- * @returns The `AppClient` instance
269
- */
270
- async getAppClientByNetwork(params) {
271
- if (!this._algorand) {
272
- throw new Error('Attempt to get app client from a ClientManager without an Algorand client');
273
- }
274
- return AppClient.fromNetwork({ ...params, algorand: this._algorand });
275
- }
276
- /**
277
- * Returns a new typed client, resolving the app by creator address and name.
278
- * @param typedClient The typed client type to use
279
- * @param params The params to resolve the app by creator address and name
280
- * @example Use name in ARC-32 / ARC-56 app spec
281
- * ```typescript
282
- * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {
283
- * creatorAddress: "CREATORADDRESS",
284
- * defaultSender: alice,
285
- * })
286
- * ```
287
- * @example Specify name
288
- * ```typescript
289
- * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {
290
- * creatorAddress: "CREATORADDRESS",
291
- * name: "contract-name",
292
- * defaultSender: alice,
293
- * })
294
- * ```
295
- * @returns The typed client instance
296
- */
297
- async getTypedAppClientByCreatorAndName(typedClient, params) {
298
- if (!this._algorand) {
299
- throw new Error('Attempt to get app client from a ClientManager without an Algorand client');
300
- }
301
- return typedClient.fromCreatorAndName({ ...params, algorand: this._algorand });
302
- }
303
- /**
304
- * Returns a new typed client, resolving the app by app ID.
305
- * @param typedClient The typed client type to use
306
- * @param params The params to resolve the app by ID
307
- * @example
308
- * ```typescript
309
- * const appClient = clientManager.getTypedAppClientById(MyContractClient, {
310
- * appId: 12345n,
311
- * defaultSender: alice,
312
- * })
313
- * ```
314
- * @returns The typed client instance
315
- */
316
- getTypedAppClientById(typedClient, params) {
317
- if (!this._algorand) {
318
- throw new Error('Attempt to get app client from a ClientManager without an Algorand client');
319
- }
320
- return new typedClient({ ...params, algorand: this._algorand });
321
- }
322
- /**
323
- * Returns a new typed client, resolves the app ID for the current network based on
324
- * pre-determined network-specific app IDs specified in the ARC-56 app spec.
325
- *
326
- * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
327
- * @param typedClient The typed client type to use
328
- * @param params The params to resolve the app by network
329
- * @example
330
- * ```typescript
331
- * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {
332
- * defaultSender: alice,
333
- * })
334
- * ```
335
- * @returns The typed client instance
336
- */
337
- getTypedAppClientByNetwork(typedClient, params) {
338
- if (!this._algorand) {
339
- throw new Error('Attempt to get app client from a ClientManager without an Algorand client');
340
- }
341
- return typedClient.fromNetwork({ ...params, algorand: this._algorand });
342
- }
343
- /**
344
- * Returns a new typed app factory.
345
- * @param typedFactory The typed factory type to use
346
- * @param params The params to resolve the factory by
347
- * @example
348
- * ```typescript
349
- * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {
350
- * sender: alice,
351
- * })
352
- * ```
353
- * @returns The typed client instance
354
- */
355
- getTypedAppFactory(typedFactory, params) {
356
- if (!this._algorand) {
357
- throw new Error('Attempt to get app factory from a ClientManager without an Algorand client');
358
- }
359
- return new typedFactory({ ...params, algorand: this._algorand });
360
- }
361
- /**
362
- * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)
363
- *
364
- * 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`.
365
- *
366
- * 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`.
367
- *
368
- * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.
369
- *
370
- * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
371
- * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
372
- * @example
373
- * ```typescript
374
- * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()
375
- * ```
376
- * @returns The config for algod, indexer and kmd
377
- */
378
- static getConfigFromEnvironmentOrLocalNet() {
379
- if (!process || !process.env) {
380
- throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead');
381
- }
382
- const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER
383
- ? [
384
- ClientManager.getAlgodConfigFromEnvironment(),
385
- process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,
386
- !process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')
387
- ? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }
388
- : undefined,
389
- ]
390
- : [
391
- ClientManager.getDefaultLocalNetConfig('algod'),
392
- ClientManager.getDefaultLocalNetConfig('indexer'),
393
- ClientManager.getDefaultLocalNetConfig('kmd'),
394
- ];
395
- return {
396
- algodConfig,
397
- indexerConfig,
398
- kmdConfig,
399
- };
400
- }
401
- /**
402
- * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)
403
- *
404
- * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
405
- * @returns The Algod client configuration
406
- * @throws Error if `process.env.ALGOD_SERVER` is not defined
407
- * @example
408
- * ```typescript
409
- * const config = ClientManager.getAlgodConfigFromEnvironment()
410
- * ```
411
- */
412
- static getAlgodConfigFromEnvironment() {
413
- if (!process || !process.env) {
414
- throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
415
- }
416
- if (!process.env.ALGOD_SERVER) {
417
- throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables');
418
- }
419
- return {
420
- server: process.env.ALGOD_SERVER,
421
- port: process.env.ALGOD_PORT,
422
- token: process.env.ALGOD_TOKEN,
423
- };
424
- }
425
- /**
426
- * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).
427
- *
428
- * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
429
- * @returns The Indexer client configuration
430
- * @throws Error if `process.env.INDEXER_SERVER` is not defined
431
- * @example
432
- * ```typescript
433
- * const config = ClientManager.getIndexerConfigFromEnvironment()
434
- * ```
435
- */
436
- static getIndexerConfigFromEnvironment() {
437
- if (!process || !process.env) {
438
- throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead');
439
- }
440
- if (!process.env.INDEXER_SERVER) {
441
- throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables');
442
- }
443
- return {
444
- server: process.env.INDEXER_SERVER,
445
- port: process.env.INDEXER_PORT,
446
- token: process.env.INDEXER_TOKEN,
447
- };
448
- }
449
- /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.
450
- *
451
- * @param network Which network to connect to - TestNet or MainNet
452
- * @param config Which algod config to return - Algod or Indexer
453
- * @returns The AlgoNode client configuration
454
- * @example
455
- * ```typescript
456
- * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')
457
- * ```
458
- */
459
- static getAlgoNodeConfig(network, config) {
460
- return {
461
- server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,
462
- port: 443,
463
- };
464
- }
465
- /** Returns the Algorand configuration to point to the default LocalNet.
466
- *
467
- * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
468
- * @returns The LocalNet client configuration
469
- * @example
470
- * ```typescript
471
- * const config = ClientManager.getDefaultLocalNetConfig('algod')
472
- * ```
473
- */
474
- static getDefaultLocalNetConfig(configOrPort) {
475
- return {
476
- server: `http://localhost`,
477
- port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,
478
- token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
479
- };
480
- }
481
- /**
482
- * Returns an algod SDK client that automatically retries on idempotent calls.
483
- *
484
- * @param config The config of the client
485
- * @returns The Algod client
486
- * @example AlgoNode (testnet)
487
- * ```typescript
488
- * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))
489
- * await algod.healthCheck().do()
490
- * ```
491
- * @example AlgoNode (mainnet)
492
- * ```typescript
493
- * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))
494
- * await algod.healthCheck().do()
495
- * ```
496
- * @example Custom (e.g. default LocalNet)
497
- * ```typescript
498
- * const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
499
- * await algod.healthCheck().do()
500
- * ```
501
- */
502
- static getAlgodClient(config) {
503
- const { token, server, port } = config;
504
- const tokenHeader = typeof token === 'string' ? { 'X-Algo-API-Token': token } : (token ?? {});
505
- const httpClientWithRetry = new AlgoHttpClientWithRetry(tokenHeader, server, port);
506
- return new algosdk.Algodv2(httpClientWithRetry, server);
507
- }
508
- /**
509
- * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
510
- *
511
- * @returns The Algod client
512
- * @example
513
- * ```typescript
514
- * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
515
- * const algod = ClientManager.getAlgodClientFromEnvironment()
516
- * await algod.healthCheck().do()
517
- * ```
518
- */
519
- static getAlgodClientFromEnvironment() {
520
- return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment());
521
- }
522
- /**
523
- * Returns an indexer SDK client that automatically retries on idempotent calls
524
- *
525
- * @param config The config of the client
526
- * @returns The Indexer client
527
- * @example AlgoNode (testnet)
528
- * ```typescript
529
- * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))
530
- * await indexer.makeHealthCheck().do()
531
- * ```
532
- * @example AlgoNode (mainnet)
533
- * ```typescript
534
- * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))
535
- * await indexer.makeHealthCheck().do()
536
- * ```
537
- * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
538
- * ```typescript
539
- * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
540
- * await indexer.makeHealthCheck().do()
541
- * ```
542
- */
543
- static getIndexerClient(config) {
544
- const { token, server, port } = config;
545
- const tokenHeader = typeof token === 'string' ? { 'X-Indexer-API-Token': token } : (token ?? {});
546
- const httpClientWithRetry = new AlgoHttpClientWithRetry(tokenHeader, server, port);
547
- return new Indexer(httpClientWithRetry);
548
- }
549
- /**
550
- * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
551
- *
552
- * @returns The Indexer client
553
- * @example
554
- *
555
- * ```typescript
556
- * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
557
- * const indexer = ClientManager.getIndexerClientFromEnvironment()
558
- * await indexer.makeHealthCheck().do()
559
- * ```
560
- */
561
- static getIndexerClientFromEnvironment() {
562
- return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment());
563
- }
564
- /**
565
- * Returns a KMD SDK client.
566
- *
567
- * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.
568
- *
569
- * @param config The config for the client
570
- * @returns The KMD client
571
- * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
572
- * ```typescript
573
- * const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
574
- * ```
575
- */
576
- static getKmdClient(config) {
577
- const { token, server, port } = config;
578
- return new Kmd(token, server, port);
579
- }
580
- /**
581
- * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
582
- *
583
- * @returns The KMD client
584
- * @example
585
- * ```typescript
586
- * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
587
- * const kmd = ClientManager.getKmdClientFromEnvironment()
588
- * ```
589
- */
590
- static getKmdClientFromEnvironment() {
591
- // We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions
592
- // (e.g. same token and server as algod and port 4002 by default)
593
- return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' });
594
- }
595
- }
596
-
11
+ var ClientManager = class ClientManager {
12
+ _algod;
13
+ _indexer;
14
+ _kmd;
15
+ _algorand;
16
+ /**
17
+ * algosdk clients or config for interacting with the official Algorand APIs.
18
+ * @param clientsOrConfig The clients or config to use
19
+ * @example Algod client only
20
+ * ```typescript
21
+ * const clientManager = new ClientManager({ algod: algodClient })
22
+ * ```
23
+ * @example All clients
24
+ * ```typescript
25
+ * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })
26
+ * ```
27
+ * @example Algod config only
28
+ * ```typescript
29
+ * const clientManager = new ClientManager({ algodConfig })
30
+ * ```
31
+ * @example All client configs
32
+ * ```typescript
33
+ * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })
34
+ * ```
35
+ */
36
+ constructor(clientsOrConfig, algorandClient) {
37
+ const _clients = "algod" in clientsOrConfig ? clientsOrConfig : {
38
+ algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),
39
+ indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : void 0,
40
+ kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : void 0
41
+ };
42
+ this._algod = _clients.algod;
43
+ this._indexer = _clients.indexer;
44
+ this._kmd = _clients.kmd;
45
+ this._algorand = algorandClient;
46
+ }
47
+ /**
48
+ * Returns an algosdk Algod API client.
49
+ * @returns The Algod client
50
+ */
51
+ get algod() {
52
+ return this._algod;
53
+ }
54
+ /**
55
+ * Returns an algosdk Indexer API client or throws an error if it's not been provided.
56
+ * @returns The Indexer client
57
+ * @throws Error if no Indexer client is configured
58
+ */
59
+ get indexer() {
60
+ if (!this._indexer) throw new Error("Attempt to use Indexer client in AlgoKit instance with no Indexer configured");
61
+ return this._indexer;
62
+ }
63
+ /**
64
+ * Returns an algosdk Indexer API client or `undefined` if it's not been provided.
65
+ * @returns The Indexer client or `undefined`
66
+ */
67
+ get indexerIfPresent() {
68
+ return this._indexer;
69
+ }
70
+ /**
71
+ * Returns an algosdk KMD API client or throws an error if it's not been provided.
72
+ * @returns The KMD client
73
+ * @throws Error if no KMD client is configured
74
+ */
75
+ get kmd() {
76
+ if (!this._kmd) throw new Error("Attempt to use Kmd client in AlgoKit instance with no Kmd configured");
77
+ return this._kmd;
78
+ }
79
+ _getNetworkPromise;
80
+ /**
81
+ * Get details about the current network.
82
+ * @example Getting genesis ID
83
+ * ```typescript
84
+ * const network = await networkClient.network()
85
+ * const genesisId = network.genesisId
86
+ * ```
87
+ * @returns The current network details
88
+ */
89
+ async network() {
90
+ if (!this._getNetworkPromise) this._getNetworkPromise = this._algod.getTransactionParams().do();
91
+ const params = await this._getNetworkPromise;
92
+ return {
93
+ isTestNet: [
94
+ "testnet-v1.0",
95
+ "testnet-v1",
96
+ "testnet"
97
+ ].includes(params.genesisID ?? "unknown"),
98
+ isMainNet: [
99
+ "mainnet-v1.0",
100
+ "mainnet-v1",
101
+ "mainnet"
102
+ ].includes(params.genesisID ?? "unknown"),
103
+ isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisID ?? "unknown"),
104
+ genesisId: params.genesisID ?? "unknown",
105
+ genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString("base64") : "unknown"
106
+ };
107
+ }
108
+ /**
109
+ * Returns true if the given network genesisId is associated with a LocalNet network.
110
+ * @param genesisId The network genesis ID
111
+ * @returns Whether the given genesis ID is associated with a LocalNet network
112
+ * @example
113
+ * ```typescript
114
+ * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')
115
+ * ```
116
+ */
117
+ static genesisIdIsLocalNet(genesisId) {
118
+ return genesisIdIsLocalNet(genesisId);
119
+ }
120
+ /**
121
+ * Returns true if the current network is LocalNet.
122
+ * @returns True if the current network is LocalNet.
123
+ * @example
124
+ * ```typescript
125
+ * const isLocalNet = await clientManager.isLocalNet()
126
+ * ```
127
+ */
128
+ async isLocalNet() {
129
+ return (await this.network()).isLocalNet;
130
+ }
131
+ /**
132
+ * Returns true if the current network is TestNet.
133
+ * @returns True if the current network is TestNet.
134
+ * @example
135
+ * ```typescript
136
+ * const isTestNet = await clientManager.isTestNet()
137
+ * ```
138
+ */
139
+ async isTestNet() {
140
+ return (await this.network()).isTestNet;
141
+ }
142
+ /**
143
+ * Returns true if the current network is MainNet.
144
+ * @returns True if the current network is MainNet.
145
+ * @example
146
+ * ```typescript
147
+ * const isMainNet = await clientManager.isMainNet()
148
+ * ```
149
+ */
150
+ async isMainNet() {
151
+ return (await this.network()).isMainNet;
152
+ }
153
+ /**
154
+ * Returns a TestNet Dispenser API client.
155
+ *
156
+ * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.
157
+ *
158
+ * @param params An object containing parameters for the TestNetDispenserApiClient class.
159
+ * @example
160
+ * const client = clientManager.getTestNetDispenser(
161
+ * {
162
+ * authToken: 'your_auth_token',
163
+ * requestTimeout: 15,
164
+ * }
165
+ * )
166
+ *
167
+ * @returns An instance of the TestNetDispenserApiClient class.
168
+ */
169
+ getTestNetDispenser(params) {
170
+ return new TestNetDispenserApiClient(params);
171
+ }
172
+ /**
173
+ * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.
174
+ *
175
+ * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.
176
+ *
177
+ * @param params An object containing parameters for the TestNetDispenserApiClient class.
178
+ * @example
179
+ * const client = clientManager.getTestNetDispenserFromEnvironment(
180
+ * {
181
+ * requestTimeout: 15,
182
+ * }
183
+ * )
184
+ *
185
+ * @returns An instance of the TestNetDispenserApiClient class.
186
+ */
187
+ getTestNetDispenserFromEnvironment(params) {
188
+ return new TestNetDispenserApiClient(params ? {
189
+ ...params,
190
+ authToken: ""
191
+ } : void 0);
192
+ }
193
+ /**
194
+ * Returns a new `AppFactory` client
195
+ * @param params The parameters to create the app factory
196
+ * @example Basic example
197
+ * ```typescript
198
+ * const factory = clientManager.getAppFactory({
199
+ * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\/}',
200
+ * })
201
+ * ```
202
+ * @example Advanced example
203
+ * ```typescript
204
+ * const factory = clientManager.getAppFactory({
205
+ * appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,
206
+ * defaultSender: "SENDERADDRESS",
207
+ * appName: "OverriddenAppName",
208
+ * version: "2.0.0",
209
+ * updatable: true,
210
+ * deletable: false,
211
+ * deployTimeParams: { ONE: 1, TWO: 'value' }
212
+ * })
213
+ * ```
214
+ * @returns The `AppFactory` instance
215
+ */
216
+ getAppFactory(params) {
217
+ if (!this._algorand) throw new Error("Attempt to get app factory from a ClientManager without an Algorand client");
218
+ return new AppFactory({
219
+ ...params,
220
+ algorand: this._algorand
221
+ });
222
+ }
223
+ /**
224
+ * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.
225
+ * This method resolves the app ID by looking up the creator address and name
226
+ * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
227
+ * @param params The parameters to create the app client
228
+ * @example Basic
229
+ * ```typescript
230
+ * const appClient = clientManager.getAppClientByCreatorAndName({
231
+ * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\}',
232
+ * // appId resolved by looking for app ID of named app by this creator
233
+ * creatorAddress: 'CREATORADDRESS',
234
+ * })
235
+ * ```
236
+ * @returns The `AppClient` instance
237
+ */
238
+ getAppClientByCreatorAndName(params) {
239
+ if (!this._algorand) throw new Error("Attempt to get app client from a ClientManager without an Algorand client");
240
+ return AppClient.fromCreatorAndName({
241
+ ...params,
242
+ algorand: this._algorand
243
+ });
244
+ }
245
+ /**
246
+ * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.
247
+ * @param params The parameters to create the app client
248
+ * @example Basic
249
+ * ```typescript
250
+ * const appClient = clientManager.getAppClientById({
251
+ * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\}',
252
+ * appId: 12345n,
253
+ * })
254
+ * ```
255
+ * @returns The `AppClient` instance
256
+ */
257
+ getAppClientById(params) {
258
+ if (!this._algorand) throw new Error("Attempt to get app client from a ClientManager without an Algorand client");
259
+ return new AppClient({
260
+ ...params,
261
+ algorand: this._algorand
262
+ });
263
+ }
264
+ /**
265
+ * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.
266
+ * This method resolves the app ID for the current network based on
267
+ * pre-determined network-specific app IDs specified in the ARC-56 app spec.
268
+ *
269
+ * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
270
+ * @param params The parameters to create the app client
271
+ * @example Basic
272
+ * ```typescript
273
+ * const appClient = clientManager.getAppClientByNetwork({
274
+ * appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\}',
275
+ * // appId resolved by using ARC-56 spec to find app ID for current network
276
+ * })
277
+ * ```
278
+ * @returns The `AppClient` instance
279
+ */
280
+ async getAppClientByNetwork(params) {
281
+ if (!this._algorand) throw new Error("Attempt to get app client from a ClientManager without an Algorand client");
282
+ return AppClient.fromNetwork({
283
+ ...params,
284
+ algorand: this._algorand
285
+ });
286
+ }
287
+ /**
288
+ * Returns a new typed client, resolving the app by creator address and name.
289
+ * @param typedClient The typed client type to use
290
+ * @param params The params to resolve the app by creator address and name
291
+ * @example Use name in ARC-32 / ARC-56 app spec
292
+ * ```typescript
293
+ * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {
294
+ * creatorAddress: "CREATORADDRESS",
295
+ * defaultSender: alice,
296
+ * })
297
+ * ```
298
+ * @example Specify name
299
+ * ```typescript
300
+ * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {
301
+ * creatorAddress: "CREATORADDRESS",
302
+ * name: "contract-name",
303
+ * defaultSender: alice,
304
+ * })
305
+ * ```
306
+ * @returns The typed client instance
307
+ */
308
+ async getTypedAppClientByCreatorAndName(typedClient, params) {
309
+ if (!this._algorand) throw new Error("Attempt to get app client from a ClientManager without an Algorand client");
310
+ return typedClient.fromCreatorAndName({
311
+ ...params,
312
+ algorand: this._algorand
313
+ });
314
+ }
315
+ /**
316
+ * Returns a new typed client, resolving the app by app ID.
317
+ * @param typedClient The typed client type to use
318
+ * @param params The params to resolve the app by ID
319
+ * @example
320
+ * ```typescript
321
+ * const appClient = clientManager.getTypedAppClientById(MyContractClient, {
322
+ * appId: 12345n,
323
+ * defaultSender: alice,
324
+ * })
325
+ * ```
326
+ * @returns The typed client instance
327
+ */
328
+ getTypedAppClientById(typedClient, params) {
329
+ if (!this._algorand) throw new Error("Attempt to get app client from a ClientManager without an Algorand client");
330
+ return new typedClient({
331
+ ...params,
332
+ algorand: this._algorand
333
+ });
334
+ }
335
+ /**
336
+ * Returns a new typed client, resolves the app ID for the current network based on
337
+ * pre-determined network-specific app IDs specified in the ARC-56 app spec.
338
+ *
339
+ * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
340
+ * @param typedClient The typed client type to use
341
+ * @param params The params to resolve the app by network
342
+ * @example
343
+ * ```typescript
344
+ * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {
345
+ * defaultSender: alice,
346
+ * })
347
+ * ```
348
+ * @returns The typed client instance
349
+ */
350
+ getTypedAppClientByNetwork(typedClient, params) {
351
+ if (!this._algorand) throw new Error("Attempt to get app client from a ClientManager without an Algorand client");
352
+ return typedClient.fromNetwork({
353
+ ...params,
354
+ algorand: this._algorand
355
+ });
356
+ }
357
+ /**
358
+ * Returns a new typed app factory.
359
+ * @param typedFactory The typed factory type to use
360
+ * @param params The params to resolve the factory by
361
+ * @example
362
+ * ```typescript
363
+ * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {
364
+ * sender: alice,
365
+ * })
366
+ * ```
367
+ * @returns The typed client instance
368
+ */
369
+ getTypedAppFactory(typedFactory, params) {
370
+ if (!this._algorand) throw new Error("Attempt to get app factory from a ClientManager without an Algorand client");
371
+ return new typedFactory({
372
+ ...params,
373
+ algorand: this._algorand
374
+ });
375
+ }
376
+ /**
377
+ * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)
378
+ *
379
+ * 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`.
380
+ *
381
+ * 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`.
382
+ *
383
+ * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.
384
+ *
385
+ * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
386
+ * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
387
+ * @example
388
+ * ```typescript
389
+ * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()
390
+ * ```
391
+ * @returns The config for algod, indexer and kmd
392
+ */
393
+ static getConfigFromEnvironmentOrLocalNet() {
394
+ if (!process || !process.env) throw new Error("Attempt to get default client configuration from a non Node.js context; supply the config instead");
395
+ const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER ? [
396
+ ClientManager.getAlgodConfigFromEnvironment(),
397
+ process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : void 0,
398
+ !process.env.ALGOD_SERVER.includes("mainnet") && !process.env.ALGOD_SERVER.includes("testnet") ? {
399
+ ...ClientManager.getAlgodConfigFromEnvironment(),
400
+ port: process?.env?.KMD_PORT ?? "4002"
401
+ } : void 0
402
+ ] : [
403
+ ClientManager.getDefaultLocalNetConfig("algod"),
404
+ ClientManager.getDefaultLocalNetConfig("indexer"),
405
+ ClientManager.getDefaultLocalNetConfig("kmd")
406
+ ];
407
+ return {
408
+ algodConfig,
409
+ indexerConfig,
410
+ kmdConfig
411
+ };
412
+ }
413
+ /**
414
+ * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)
415
+ *
416
+ * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
417
+ * @returns The Algod client configuration
418
+ * @throws Error if `process.env.ALGOD_SERVER` is not defined
419
+ * @example
420
+ * ```typescript
421
+ * const config = ClientManager.getAlgodConfigFromEnvironment()
422
+ * ```
423
+ */
424
+ static getAlgodConfigFromEnvironment() {
425
+ if (!process || !process.env) throw new Error("Attempt to get default algod configuration from a non Node.js context; supply the config instead");
426
+ if (!process.env.ALGOD_SERVER) throw new Error("Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables");
427
+ return {
428
+ server: process.env.ALGOD_SERVER,
429
+ port: process.env.ALGOD_PORT,
430
+ token: process.env.ALGOD_TOKEN
431
+ };
432
+ }
433
+ /**
434
+ * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).
435
+ *
436
+ * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
437
+ * @returns The Indexer client configuration
438
+ * @throws Error if `process.env.INDEXER_SERVER` is not defined
439
+ * @example
440
+ * ```typescript
441
+ * const config = ClientManager.getIndexerConfigFromEnvironment()
442
+ * ```
443
+ */
444
+ static getIndexerConfigFromEnvironment() {
445
+ if (!process || !process.env) throw new Error("Attempt to get default indexer configuration from a non Node.js context; supply the config instead");
446
+ if (!process.env.INDEXER_SERVER) throw new Error("Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables");
447
+ return {
448
+ server: process.env.INDEXER_SERVER,
449
+ port: process.env.INDEXER_PORT,
450
+ token: process.env.INDEXER_TOKEN
451
+ };
452
+ }
453
+ /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.
454
+ *
455
+ * @param network Which network to connect to - TestNet or MainNet
456
+ * @param config Which algod config to return - Algod or Indexer
457
+ * @returns The AlgoNode client configuration
458
+ * @example
459
+ * ```typescript
460
+ * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')
461
+ * ```
462
+ */
463
+ static getAlgoNodeConfig(network, config) {
464
+ return {
465
+ server: `https://${network}-${config === "algod" ? "api" : "idx"}.algonode.cloud/`,
466
+ port: 443
467
+ };
468
+ }
469
+ /** Returns the Algorand configuration to point to the default LocalNet.
470
+ *
471
+ * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
472
+ * @returns The LocalNet client configuration
473
+ * @example
474
+ * ```typescript
475
+ * const config = ClientManager.getDefaultLocalNetConfig('algod')
476
+ * ```
477
+ */
478
+ static getDefaultLocalNetConfig(configOrPort) {
479
+ return {
480
+ server: `http://localhost`,
481
+ port: configOrPort === "algod" ? 4001 : configOrPort === "indexer" ? 8980 : configOrPort === "kmd" ? 4002 : configOrPort,
482
+ token: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
483
+ };
484
+ }
485
+ /**
486
+ * Returns an algod SDK client that automatically retries on idempotent calls.
487
+ *
488
+ * @param config The config of the client
489
+ * @returns The Algod client
490
+ * @example AlgoNode (testnet)
491
+ * ```typescript
492
+ * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))
493
+ * await algod.healthCheck().do()
494
+ * ```
495
+ * @example AlgoNode (mainnet)
496
+ * ```typescript
497
+ * const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))
498
+ * await algod.healthCheck().do()
499
+ * ```
500
+ * @example Custom (e.g. default LocalNet)
501
+ * ```typescript
502
+ * const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
503
+ * await algod.healthCheck().do()
504
+ * ```
505
+ */
506
+ static getAlgodClient(config) {
507
+ const { token, server, port } = config;
508
+ const httpClientWithRetry = new AlgoHttpClientWithRetry(typeof token === "string" ? { "X-Algo-API-Token": token } : token ?? {}, server, port);
509
+ return new algosdk.Algodv2(httpClientWithRetry, server);
510
+ }
511
+ /**
512
+ * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
513
+ *
514
+ * @returns The Algod client
515
+ * @example
516
+ * ```typescript
517
+ * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
518
+ * const algod = ClientManager.getAlgodClientFromEnvironment()
519
+ * await algod.healthCheck().do()
520
+ * ```
521
+ */
522
+ static getAlgodClientFromEnvironment() {
523
+ return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment());
524
+ }
525
+ /**
526
+ * Returns an indexer SDK client that automatically retries on idempotent calls
527
+ *
528
+ * @param config The config of the client
529
+ * @returns The Indexer client
530
+ * @example AlgoNode (testnet)
531
+ * ```typescript
532
+ * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))
533
+ * await indexer.makeHealthCheck().do()
534
+ * ```
535
+ * @example AlgoNode (mainnet)
536
+ * ```typescript
537
+ * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))
538
+ * await indexer.makeHealthCheck().do()
539
+ * ```
540
+ * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
541
+ * ```typescript
542
+ * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
543
+ * await indexer.makeHealthCheck().do()
544
+ * ```
545
+ */
546
+ static getIndexerClient(config) {
547
+ const { token, server, port } = config;
548
+ return new Indexer(new AlgoHttpClientWithRetry(typeof token === "string" ? { "X-Indexer-API-Token": token } : token ?? {}, server, port));
549
+ }
550
+ /**
551
+ * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
552
+ *
553
+ * @returns The Indexer client
554
+ * @example
555
+ *
556
+ * ```typescript
557
+ * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
558
+ * const indexer = ClientManager.getIndexerClientFromEnvironment()
559
+ * await indexer.makeHealthCheck().do()
560
+ * ```
561
+ */
562
+ static getIndexerClientFromEnvironment() {
563
+ return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment());
564
+ }
565
+ /**
566
+ * Returns a KMD SDK client.
567
+ *
568
+ * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.
569
+ *
570
+ * @param config The config for the client
571
+ * @returns The KMD client
572
+ * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)
573
+ * ```typescript
574
+ * const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
575
+ * ```
576
+ */
577
+ static getKmdClient(config) {
578
+ const { token, server, port } = config;
579
+ return new Kmd(token, server, port);
580
+ }
581
+ /**
582
+ * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
583
+ *
584
+ * @returns The KMD client
585
+ * @example
586
+ * ```typescript
587
+ * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
588
+ * const kmd = ClientManager.getKmdClientFromEnvironment()
589
+ * ```
590
+ */
591
+ static getKmdClientFromEnvironment() {
592
+ return ClientManager.getKmdClient({
593
+ ...ClientManager.getAlgodConfigFromEnvironment(),
594
+ port: process?.env?.KMD_PORT ?? "4002"
595
+ });
596
+ }
597
+ };
598
+ //#endregion
597
599
  export { ClientManager };
598
- //# sourceMappingURL=client-manager.mjs.map
600
+
601
+ //# sourceMappingURL=client-manager.mjs.map