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

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,320 +1,323 @@
1
- import { AccountManager } from './account-manager.mjs';
2
- import { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator.mjs';
3
- import { AlgorandClientTransactionSender } from './algorand-client-transaction-sender.mjs';
4
- import { AppDeployer } from './app-deployer.mjs';
5
- import { AppManager } from './app-manager.mjs';
6
- import { AssetManager } from './asset-manager.mjs';
7
- import { ClientManager } from './client-manager.mjs';
8
- import { TransactionComposer } from './composer.mjs';
9
-
1
+ import { AppManager } from "./app-manager.mjs";
2
+ import { TransactionComposer } from "./composer.mjs";
3
+ import { AlgorandClientTransactionCreator } from "./algorand-client-transaction-creator.mjs";
4
+ import { AlgorandClientTransactionSender } from "./algorand-client-transaction-sender.mjs";
5
+ import { AssetManager } from "./asset-manager.mjs";
6
+ import { AppDeployer } from "./app-deployer.mjs";
7
+ import { ClientManager } from "./client-manager.mjs";
8
+ import { AccountManager } from "./account-manager.mjs";
9
+ //#region src/types/algorand-client.ts
10
10
  /**
11
- * A client that brokers easy access to Algorand functionality.
12
- */
13
- class AlgorandClient {
14
- constructor(config) {
15
- this._cachedSuggestedParamsTimeout = 3000; // three seconds
16
- this._defaultValidityWindow = undefined;
17
- /**
18
- * A set of error transformers to use when an error is caught in simulate or execute
19
- * `registerErrorTransformer` and `unregisterErrorTransformer` can be used to add and remove
20
- * error transformers from the set.
21
- */
22
- this._errorTransformers = new Set();
23
- this._clientManager = new ClientManager(config, this);
24
- this._accountManager = new AccountManager(this._clientManager);
25
- this._appManager = new AppManager(this._clientManager.algod);
26
- this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup());
27
- this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager, this._appManager);
28
- this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup());
29
- this._appDeployer = new AppDeployer(this._appManager, this._transactionSender, this._clientManager.indexerIfPresent);
30
- }
31
- /**
32
- * Sets the default validity window for transactions.
33
- * @param validityWindow The number of rounds between the first and last valid rounds
34
- * @returns The `AlgorandClient` so method calls can be chained
35
- * @example
36
- * ```typescript
37
- * const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);
38
- * ```
39
- */
40
- setDefaultValidityWindow(validityWindow) {
41
- this._defaultValidityWindow = BigInt(validityWindow);
42
- return this;
43
- }
44
- /**
45
- * Sets the default signer to use if no other signer is specified.
46
- * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
47
- * @returns The `AlgorandClient` so method calls can be chained
48
- * @example
49
- * ```typescript
50
- * const signer = new SigningAccount(account, account.addr)
51
- * const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)
52
- * ```
53
- */
54
- setDefaultSigner(signer) {
55
- this._accountManager.setDefaultSigner(signer);
56
- return this;
57
- }
58
- /**
59
- * Tracks the given account (object that encapsulates an address and a signer) for later signing.
60
- * @param account The account to register, which can be a `TransactionSignerAccount` or
61
- * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
62
- * @example
63
- * ```typescript
64
- * const accountManager = AlgorandClient.mainNet()
65
- * .setSignerFromAccount(algosdk.generateAccount())
66
- * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
67
- * .setSignerFromAccount(new SigningAccount(account, sender))
68
- * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
69
- * .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
70
- * ```
71
- * @returns The `AlgorandClient` so method calls can be chained
72
- */
73
- setSignerFromAccount(account) {
74
- this._accountManager.setSignerFromAccount(account);
75
- return this;
76
- }
77
- /**
78
- * Tracks the given signer against the given sender for later signing.
79
- * @param sender The sender address to use this signer for
80
- * @param signer The signer to sign transactions with for the given sender
81
- * @returns The `AlgorandClient` so method calls can be chained
82
- * @example
83
- * ```typescript
84
- * const signer = new SigningAccount(account, account.addr)
85
- * const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)
86
- * ```
87
- */
88
- setSigner(sender, signer) {
89
- this._accountManager.setSigner(sender, signer);
90
- return this;
91
- }
92
- /**
93
- * Sets a cache value to use for suggested transaction params.
94
- * @param suggestedParams The suggested params to use
95
- * @param until A date until which to cache, or if not specified then the timeout is used
96
- * @returns The `AlgorandClient` so method calls can be chained
97
- * @example
98
- * ```typescript
99
- * const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))
100
- * ```
101
- */
102
- setSuggestedParamsCache(suggestedParams, until) {
103
- this._cachedSuggestedParams = suggestedParams;
104
- this._cachedSuggestedParamsExpiry = until ?? new Date(+new Date() + this._cachedSuggestedParamsTimeout);
105
- return this;
106
- }
107
- /**
108
- * Sets the timeout for caching suggested params.
109
- * @param timeout The timeout in milliseconds
110
- * @returns The `AlgorandClient` so method calls can be chained
111
- * @example
112
- * ```typescript
113
- * const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)
114
- * ```
115
- */
116
- setSuggestedParamsCacheTimeout(timeout) {
117
- this._cachedSuggestedParamsTimeout = timeout;
118
- return this;
119
- }
120
- /**
121
- * Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)
122
- * @returns The suggested transaction parameters.
123
- * @example
124
- * const params = await AlgorandClient.mainNet().getSuggestedParams();
125
- */
126
- async getSuggestedParams() {
127
- if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {
128
- return {
129
- ...this._cachedSuggestedParams,
130
- };
131
- }
132
- this._cachedSuggestedParams = await this._clientManager.algod.getTransactionParams().do();
133
- this._cachedSuggestedParamsExpiry = new Date(new Date().getTime() + this._cachedSuggestedParamsTimeout);
134
- return {
135
- ...this._cachedSuggestedParams,
136
- };
137
- }
138
- /**
139
- * Get clients, including algosdk clients and app clients.
140
- * @returns The `ClientManager` instance.
141
- * @example
142
- * const clientManager = AlgorandClient.mainNet().client;
143
- */
144
- get client() {
145
- return this._clientManager;
146
- }
147
- /**
148
- * Get or create accounts that can sign transactions.
149
- * @returns The `AccountManager` instance.
150
- * @example
151
- * const accountManager = AlgorandClient.mainNet().account;
152
- */
153
- get account() {
154
- return this._accountManager;
155
- }
156
- /**
157
- * Methods for interacting with assets.
158
- * @returns The `AssetManager` instance.
159
- * @example
160
- * const assetManager = AlgorandClient.mainNet().asset;
161
- */
162
- get asset() {
163
- return this._assetManager;
164
- }
165
- /**
166
- * Methods for interacting with apps.
167
- * @returns The `AppManager` instance.
168
- * @example
169
- * const appManager = AlgorandClient.mainNet().app;
170
- */
171
- get app() {
172
- return this._appManager;
173
- }
174
- /**
175
- * Methods for deploying apps and managing app deployment metadata.
176
- * @returns The `AppDeployer` instance.
177
- * @example
178
- * const deployer = AlgorandClient.mainNet().appDeployer;
179
- */
180
- get appDeployer() {
181
- return this._appDeployer;
182
- }
183
- /**
184
- * Register a function that will be used to transform an error caught when simulating or executing
185
- * composed transaction groups made from `newGroup`
186
- */
187
- registerErrorTransformer(transformer) {
188
- this._errorTransformers.add(transformer);
189
- }
190
- unregisterErrorTransformer(transformer) {
191
- this._errorTransformers.delete(transformer);
192
- }
193
- /** Start a new `TransactionComposer` transaction group
194
- * @returns A new instance of `TransactionComposer`.
195
- * @example
196
- * const composer = AlgorandClient.mainNet().newGroup();
197
- * const result = await composer.addTransaction(payment).send()
198
- */
199
- newGroup() {
200
- return new TransactionComposer({
201
- algod: this.client.algod,
202
- getSigner: (addr) => this.account.getSigner(addr),
203
- getSuggestedParams: () => this.getSuggestedParams(),
204
- defaultValidityWindow: this._defaultValidityWindow,
205
- appManager: this._appManager,
206
- errorTransformers: [...this._errorTransformers],
207
- });
208
- }
209
- /**
210
- * Methods for sending a transaction.
211
- * @returns The `AlgorandClientTransactionSender` instance.
212
- * @example
213
- * const result = await AlgorandClient.mainNet().send.payment({
214
- * sender: "SENDERADDRESS",
215
- * receiver: "RECEIVERADDRESS",
216
- * amount: algo(1)
217
- * })
218
- */
219
- get send() {
220
- return this._transactionSender;
221
- }
222
- /**
223
- * Methods for creating a transaction.
224
- * @returns The `AlgorandClientTransactionCreator` instance.
225
- * @example
226
- * const payment = await AlgorandClient.mainNet().createTransaction.payment({
227
- * sender: "SENDERADDRESS",
228
- * receiver: "RECEIVERADDRESS",
229
- * amount: algo(1)
230
- * })
231
- */
232
- get createTransaction() {
233
- return this._transactionCreator;
234
- }
235
- // Static methods to create an `AlgorandClient`
236
- /**
237
- * Creates an `AlgorandClient` pointing at default LocalNet ports and API token.
238
- * @returns An instance of the `AlgorandClient`.
239
- * @example
240
- * const algorand = AlgorandClient.defaultLocalNet();
241
- */
242
- static defaultLocalNet() {
243
- return new AlgorandClient({
244
- algodConfig: ClientManager.getDefaultLocalNetConfig('algod'),
245
- indexerConfig: ClientManager.getDefaultLocalNetConfig('indexer'),
246
- kmdConfig: ClientManager.getDefaultLocalNetConfig('kmd'),
247
- });
248
- }
249
- /**
250
- * Creates an `AlgorandClient` pointing at TestNet using AlgoNode.
251
- * @returns An instance of the `AlgorandClient`.
252
- * @example
253
- * const algorand = AlgorandClient.testNet();
254
- */
255
- static testNet() {
256
- return new AlgorandClient({
257
- algodConfig: ClientManager.getAlgoNodeConfig('testnet', 'algod'),
258
- indexerConfig: ClientManager.getAlgoNodeConfig('testnet', 'indexer'),
259
- kmdConfig: undefined,
260
- });
261
- }
262
- /**
263
- * Creates an `AlgorandClient` pointing at MainNet using AlgoNode.
264
- * @returns An instance of the `AlgorandClient`.
265
- * @example
266
- * const algorand = AlgorandClient.mainNet();
267
- */
268
- static mainNet() {
269
- return new AlgorandClient({
270
- algodConfig: ClientManager.getAlgoNodeConfig('mainnet', 'algod'),
271
- indexerConfig: ClientManager.getAlgoNodeConfig('mainnet', 'indexer'),
272
- kmdConfig: undefined,
273
- });
274
- }
275
- /**
276
- * Creates an `AlgorandClient` pointing to the given client(s).
277
- * @param clients The clients to use.
278
- * @returns An instance of the `AlgorandClient`.
279
- * @example
280
- * const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });
281
- */
282
- static fromClients(clients) {
283
- return new AlgorandClient(clients);
284
- }
285
- /**
286
- * Creates an `AlgorandClient` loading the configuration from environment variables.
287
- *
288
- * Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.
289
- *
290
- * Expects to be called from a Node.js environment.
291
- *
292
- * If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
293
- *
294
- * If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
295
- *
296
- * If either aren't defined it will use the default LocalNet config.
297
- *
298
- * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
299
- * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
300
- * @returns An instance of the `AlgorandClient`.
301
- * @example
302
- * const client = AlgorandClient.fromEnvironment();
303
- */
304
- static fromEnvironment() {
305
- return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet());
306
- }
307
- /**
308
- * Creates an `AlgorandClient` from the given config.
309
- * @param config The config to use.
310
- * @returns An instance of the `AlgorandClient`.
311
- * @example
312
- * const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });
313
- */
314
- static fromConfig(config) {
315
- return new AlgorandClient(config);
316
- }
317
- }
318
-
11
+ * A client that brokers easy access to Algorand functionality.
12
+ */
13
+ var AlgorandClient = class AlgorandClient {
14
+ _clientManager;
15
+ _accountManager;
16
+ _appManager;
17
+ _appDeployer;
18
+ _assetManager;
19
+ _transactionSender;
20
+ _transactionCreator;
21
+ _cachedSuggestedParams;
22
+ _cachedSuggestedParamsExpiry;
23
+ _cachedSuggestedParamsTimeout = 3e3;
24
+ _defaultValidityWindow = void 0;
25
+ /**
26
+ * A set of error transformers to use when an error is caught in simulate or execute
27
+ * `registerErrorTransformer` and `unregisterErrorTransformer` can be used to add and remove
28
+ * error transformers from the set.
29
+ */
30
+ _errorTransformers = /* @__PURE__ */ new Set();
31
+ constructor(config) {
32
+ this._clientManager = new ClientManager(config, this);
33
+ this._accountManager = new AccountManager(this._clientManager);
34
+ this._appManager = new AppManager(this._clientManager.algod);
35
+ this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup());
36
+ this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager, this._appManager);
37
+ this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup());
38
+ this._appDeployer = new AppDeployer(this._appManager, this._transactionSender, this._clientManager.indexerIfPresent);
39
+ }
40
+ /**
41
+ * Sets the default validity window for transactions.
42
+ * @param validityWindow The number of rounds between the first and last valid rounds
43
+ * @returns The `AlgorandClient` so method calls can be chained
44
+ * @example
45
+ * ```typescript
46
+ * const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);
47
+ * ```
48
+ */
49
+ setDefaultValidityWindow(validityWindow) {
50
+ this._defaultValidityWindow = BigInt(validityWindow);
51
+ return this;
52
+ }
53
+ /**
54
+ * Sets the default signer to use if no other signer is specified.
55
+ * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
56
+ * @returns The `AlgorandClient` so method calls can be chained
57
+ * @example
58
+ * ```typescript
59
+ * const signer = new SigningAccount(account, account.addr)
60
+ * const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)
61
+ * ```
62
+ */
63
+ setDefaultSigner(signer) {
64
+ this._accountManager.setDefaultSigner(signer);
65
+ return this;
66
+ }
67
+ /**
68
+ * Tracks the given account (object that encapsulates an address and a signer) for later signing.
69
+ * @param account The account to register, which can be a `TransactionSignerAccount` or
70
+ * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
71
+ * @example
72
+ * ```typescript
73
+ * const accountManager = AlgorandClient.mainNet()
74
+ * .setSignerFromAccount(algosdk.generateAccount())
75
+ * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
76
+ * .setSignerFromAccount(new SigningAccount(account, sender))
77
+ * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
78
+ * .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
79
+ * ```
80
+ * @returns The `AlgorandClient` so method calls can be chained
81
+ */
82
+ setSignerFromAccount(account) {
83
+ this._accountManager.setSignerFromAccount(account);
84
+ return this;
85
+ }
86
+ /**
87
+ * Tracks the given signer against the given sender for later signing.
88
+ * @param sender The sender address to use this signer for
89
+ * @param signer The signer to sign transactions with for the given sender
90
+ * @returns The `AlgorandClient` so method calls can be chained
91
+ * @example
92
+ * ```typescript
93
+ * const signer = new SigningAccount(account, account.addr)
94
+ * const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)
95
+ * ```
96
+ */
97
+ setSigner(sender, signer) {
98
+ this._accountManager.setSigner(sender, signer);
99
+ return this;
100
+ }
101
+ /**
102
+ * Sets a cache value to use for suggested transaction params.
103
+ * @param suggestedParams The suggested params to use
104
+ * @param until A date until which to cache, or if not specified then the timeout is used
105
+ * @returns The `AlgorandClient` so method calls can be chained
106
+ * @example
107
+ * ```typescript
108
+ * const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))
109
+ * ```
110
+ */
111
+ setSuggestedParamsCache(suggestedParams, until) {
112
+ this._cachedSuggestedParams = suggestedParams;
113
+ this._cachedSuggestedParamsExpiry = until ?? new Date(+/* @__PURE__ */ new Date() + this._cachedSuggestedParamsTimeout);
114
+ return this;
115
+ }
116
+ /**
117
+ * Sets the timeout for caching suggested params.
118
+ * @param timeout The timeout in milliseconds
119
+ * @returns The `AlgorandClient` so method calls can be chained
120
+ * @example
121
+ * ```typescript
122
+ * const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)
123
+ * ```
124
+ */
125
+ setSuggestedParamsCacheTimeout(timeout) {
126
+ this._cachedSuggestedParamsTimeout = timeout;
127
+ return this;
128
+ }
129
+ /**
130
+ * Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)
131
+ * @returns The suggested transaction parameters.
132
+ * @example
133
+ * const params = await AlgorandClient.mainNet().getSuggestedParams();
134
+ */
135
+ async getSuggestedParams() {
136
+ if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > /* @__PURE__ */ new Date())) return { ...this._cachedSuggestedParams };
137
+ this._cachedSuggestedParams = await this._clientManager.algod.getTransactionParams().do();
138
+ this._cachedSuggestedParamsExpiry = new Date((/* @__PURE__ */ new Date()).getTime() + this._cachedSuggestedParamsTimeout);
139
+ return { ...this._cachedSuggestedParams };
140
+ }
141
+ /**
142
+ * Get clients, including algosdk clients and app clients.
143
+ * @returns The `ClientManager` instance.
144
+ * @example
145
+ * const clientManager = AlgorandClient.mainNet().client;
146
+ */
147
+ get client() {
148
+ return this._clientManager;
149
+ }
150
+ /**
151
+ * Get or create accounts that can sign transactions.
152
+ * @returns The `AccountManager` instance.
153
+ * @example
154
+ * const accountManager = AlgorandClient.mainNet().account;
155
+ */
156
+ get account() {
157
+ return this._accountManager;
158
+ }
159
+ /**
160
+ * Methods for interacting with assets.
161
+ * @returns The `AssetManager` instance.
162
+ * @example
163
+ * const assetManager = AlgorandClient.mainNet().asset;
164
+ */
165
+ get asset() {
166
+ return this._assetManager;
167
+ }
168
+ /**
169
+ * Methods for interacting with apps.
170
+ * @returns The `AppManager` instance.
171
+ * @example
172
+ * const appManager = AlgorandClient.mainNet().app;
173
+ */
174
+ get app() {
175
+ return this._appManager;
176
+ }
177
+ /**
178
+ * Methods for deploying apps and managing app deployment metadata.
179
+ * @returns The `AppDeployer` instance.
180
+ * @example
181
+ * const deployer = AlgorandClient.mainNet().appDeployer;
182
+ */
183
+ get appDeployer() {
184
+ return this._appDeployer;
185
+ }
186
+ /**
187
+ * Register a function that will be used to transform an error caught when simulating or executing
188
+ * composed transaction groups made from `newGroup`
189
+ */
190
+ registerErrorTransformer(transformer) {
191
+ this._errorTransformers.add(transformer);
192
+ }
193
+ unregisterErrorTransformer(transformer) {
194
+ this._errorTransformers.delete(transformer);
195
+ }
196
+ /** Start a new `TransactionComposer` transaction group
197
+ * @returns A new instance of `TransactionComposer`.
198
+ * @example
199
+ * const composer = AlgorandClient.mainNet().newGroup();
200
+ * const result = await composer.addTransaction(payment).send()
201
+ */
202
+ newGroup() {
203
+ return new TransactionComposer({
204
+ algod: this.client.algod,
205
+ getSigner: (addr) => this.account.getSigner(addr),
206
+ getSuggestedParams: () => this.getSuggestedParams(),
207
+ defaultValidityWindow: this._defaultValidityWindow,
208
+ appManager: this._appManager,
209
+ errorTransformers: [...this._errorTransformers]
210
+ });
211
+ }
212
+ /**
213
+ * Methods for sending a transaction.
214
+ * @returns The `AlgorandClientTransactionSender` instance.
215
+ * @example
216
+ * const result = await AlgorandClient.mainNet().send.payment({
217
+ * sender: "SENDERADDRESS",
218
+ * receiver: "RECEIVERADDRESS",
219
+ * amount: algo(1)
220
+ * })
221
+ */
222
+ get send() {
223
+ return this._transactionSender;
224
+ }
225
+ /**
226
+ * Methods for creating a transaction.
227
+ * @returns The `AlgorandClientTransactionCreator` instance.
228
+ * @example
229
+ * const payment = await AlgorandClient.mainNet().createTransaction.payment({
230
+ * sender: "SENDERADDRESS",
231
+ * receiver: "RECEIVERADDRESS",
232
+ * amount: algo(1)
233
+ * })
234
+ */
235
+ get createTransaction() {
236
+ return this._transactionCreator;
237
+ }
238
+ /**
239
+ * Creates an `AlgorandClient` pointing at default LocalNet ports and API token.
240
+ * @returns An instance of the `AlgorandClient`.
241
+ * @example
242
+ * const algorand = AlgorandClient.defaultLocalNet();
243
+ */
244
+ static defaultLocalNet() {
245
+ return new AlgorandClient({
246
+ algodConfig: ClientManager.getDefaultLocalNetConfig("algod"),
247
+ indexerConfig: ClientManager.getDefaultLocalNetConfig("indexer"),
248
+ kmdConfig: ClientManager.getDefaultLocalNetConfig("kmd")
249
+ });
250
+ }
251
+ /**
252
+ * Creates an `AlgorandClient` pointing at TestNet using AlgoNode.
253
+ * @returns An instance of the `AlgorandClient`.
254
+ * @example
255
+ * const algorand = AlgorandClient.testNet();
256
+ */
257
+ static testNet() {
258
+ return new AlgorandClient({
259
+ algodConfig: ClientManager.getAlgoNodeConfig("testnet", "algod"),
260
+ indexerConfig: ClientManager.getAlgoNodeConfig("testnet", "indexer"),
261
+ kmdConfig: void 0
262
+ });
263
+ }
264
+ /**
265
+ * Creates an `AlgorandClient` pointing at MainNet using AlgoNode.
266
+ * @returns An instance of the `AlgorandClient`.
267
+ * @example
268
+ * const algorand = AlgorandClient.mainNet();
269
+ */
270
+ static mainNet() {
271
+ return new AlgorandClient({
272
+ algodConfig: ClientManager.getAlgoNodeConfig("mainnet", "algod"),
273
+ indexerConfig: ClientManager.getAlgoNodeConfig("mainnet", "indexer"),
274
+ kmdConfig: void 0
275
+ });
276
+ }
277
+ /**
278
+ * Creates an `AlgorandClient` pointing to the given client(s).
279
+ * @param clients The clients to use.
280
+ * @returns An instance of the `AlgorandClient`.
281
+ * @example
282
+ * const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });
283
+ */
284
+ static fromClients(clients) {
285
+ return new AlgorandClient(clients);
286
+ }
287
+ /**
288
+ * Creates an `AlgorandClient` loading the configuration from environment variables.
289
+ *
290
+ * Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.
291
+ *
292
+ * Expects to be called from a Node.js environment.
293
+ *
294
+ * If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
295
+ *
296
+ * If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
297
+ *
298
+ * If either aren't defined it will use the default LocalNet config.
299
+ *
300
+ * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
301
+ * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
302
+ * @returns An instance of the `AlgorandClient`.
303
+ * @example
304
+ * const client = AlgorandClient.fromEnvironment();
305
+ */
306
+ static fromEnvironment() {
307
+ return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet());
308
+ }
309
+ /**
310
+ * Creates an `AlgorandClient` from the given config.
311
+ * @param config The config to use.
312
+ * @returns An instance of the `AlgorandClient`.
313
+ * @example
314
+ * const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });
315
+ */
316
+ static fromConfig(config) {
317
+ return new AlgorandClient(config);
318
+ }
319
+ };
320
+ //#endregion
319
321
  export { AlgorandClient };
320
- //# sourceMappingURL=algorand-client.mjs.map
322
+
323
+ //# sourceMappingURL=algorand-client.mjs.map