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