@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,1508 +1,1445 @@
1
- import algosdk, { Address } from 'algosdk';
2
- import { Config } from '../config.mjs';
3
- import { encodeLease, sendAtomicTransactionComposer, getABIReturnValue } from '../transaction/transaction.mjs';
4
- import { calculateExtraProgramPages, asJson } from '../util.mjs';
5
- import { AppManager } from './app-manager.mjs';
6
- import { EventType } from './lifecycle-events.mjs';
7
- import { genesisIdIsLocalNet } from './network-client.mjs';
8
-
1
+ import { Config } from "../config.mjs";
2
+ import "./lifecycle-events.mjs";
3
+ import { asJson, calculateExtraProgramPages } from "../util.mjs";
4
+ import { encodeLease, getABIReturnValue, sendAtomicTransactionComposer } from "../transaction/transaction.mjs";
5
+ import { AppManager } from "./app-manager.mjs";
6
+ import { genesisIdIsLocalNet } from "./network-client.mjs";
7
+ import algosdk, { Address } from "algosdk";
8
+ //#region src/types/composer.ts
9
9
  var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
10
10
  var isTransactionWithSigner = algosdk.isTransactionWithSigner;
11
11
  var modelsv2 = algosdk.modelsv2;
12
12
  const address = (address) => {
13
- return typeof address === 'string' ? Address.fromString(address) : address;
13
+ return typeof address === "string" ? Address.fromString(address) : address;
14
14
  };
15
15
  const MAX_TRANSACTION_GROUP_SIZE = 16;
16
- class InvalidErrorTransformerValue extends Error {
17
- constructor(originalError, value) {
18
- super(`An error transformer returned a non-error value: ${value}. The original error before any transformation: ${originalError}`);
19
- }
20
- }
21
- class ErrorTransformerError extends Error {
22
- constructor(originalError, cause) {
23
- super(`An error transformer threw an error: ${cause}. The original error before any transformation: ${originalError} `, { cause });
24
- }
25
- }
16
+ var InvalidErrorTransformerValue = class extends Error {
17
+ constructor(originalError, value) {
18
+ super(`An error transformer returned a non-error value: ${value}. The original error before any transformation: ${originalError}`);
19
+ }
20
+ };
21
+ var ErrorTransformerError = class extends Error {
22
+ constructor(originalError, cause) {
23
+ super(`An error transformer threw an error: ${cause}. The original error before any transformation: ${originalError} `, { cause });
24
+ }
25
+ };
26
26
  /** TransactionComposer helps you compose and execute transactions as a transaction group. */
27
- class TransactionComposer {
28
- async transformError(originalError) {
29
- // Transformers only work with Error instances, so immediately return anything else
30
- if (!(originalError instanceof Error)) {
31
- return originalError;
32
- }
33
- let transformedError = originalError;
34
- for (const transformer of this.errorTransformers) {
35
- try {
36
- transformedError = await transformer(transformedError);
37
- if (!(transformedError instanceof Error)) {
38
- return new InvalidErrorTransformerValue(originalError, transformedError);
39
- }
40
- }
41
- catch (errorFromTransformer) {
42
- return new ErrorTransformerError(originalError, errorFromTransformer);
43
- }
44
- }
45
- return transformedError;
46
- }
47
- /**
48
- * Create a `TransactionComposer`.
49
- * @param params The configuration for this composer
50
- * @returns The `TransactionComposer` instance
51
- */
52
- constructor(params) {
53
- /** The ATC used to compose the group */
54
- this.atc = new algosdk.AtomicTransactionComposer();
55
- /** Map of transaction index in the atc to a max logical fee.
56
- * This is set using the value of either maxFee or staticFee.
57
- */
58
- this.txnMaxFees = new Map();
59
- /** Transactions that have not yet been composed */
60
- this.txns = [];
61
- /** The default transaction validity window */
62
- this.defaultValidityWindow = 10n;
63
- /** Whether the validity window was explicitly set on construction */
64
- this.defaultValidityWindowIsExplicit = false;
65
- this.algod = params.algod;
66
- const defaultGetSuggestedParams = () => params.algod.getTransactionParams().do();
67
- this.getSuggestedParams = params.getSuggestedParams ?? defaultGetSuggestedParams;
68
- this.getSigner = params.getSigner;
69
- this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
70
- this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== undefined;
71
- this.appManager = params.appManager ?? new AppManager(params.algod);
72
- this.errorTransformers = params.errorTransformers ?? [];
73
- }
74
- /**
75
- * Register a function that will be used to transform an error caught when simulating or executing
76
- *
77
- * @returns The composer so you can chain method calls
78
- */
79
- registerErrorTransformer(transformer) {
80
- this.errorTransformers.push(transformer);
81
- return this;
82
- }
83
- /**
84
- * Add a pre-built transaction to the transaction group.
85
- * @param transaction The pre-built transaction
86
- * @param signer Optional signer override for the transaction
87
- * @returns The composer so you can chain method calls
88
- * @example
89
- * ```typescript
90
- * composer.addTransaction(txn)
91
- * ```
92
- */
93
- addTransaction(transaction, signer) {
94
- this.txns.push({
95
- txn: transaction,
96
- signer: signer ?? this.getSigner(transaction.sender),
97
- type: 'txnWithSigner',
98
- });
99
- return this;
100
- }
101
- /**
102
- * Add a payment transaction to the transaction group.
103
- * @param params The payment transaction parameters
104
- * @returns The composer so you can chain method calls
105
- * @example Basic example
106
- * ```typescript
107
- * composer.addPayment({
108
- * sender: 'SENDERADDRESS',
109
- * receiver: 'RECEIVERADDRESS',
110
- * amount: (4).algo(),
111
- * })
112
- * ```
113
- * @example Advanced example
114
- * ```typescript
115
- * composer.addPayment({
116
- * amount: (4).algo(),
117
- * receiver: 'RECEIVERADDRESS',
118
- * sender: 'SENDERADDRESS',
119
- * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS',
120
- * lease: 'lease',
121
- * note: 'note',
122
- * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
123
- * rekeyTo: 'REKEYTOADDRESS',
124
- * // You wouldn't normally set this field
125
- * firstValidRound: 1000n,
126
- * validityWindow: 10,
127
- * extraFee: (1000).microAlgo(),
128
- * staticFee: (1000).microAlgo(),
129
- * // Max fee doesn't make sense with extraFee AND staticFee
130
- * // already specified, but here for completeness
131
- * maxFee: (3000).microAlgo(),
132
- * })
133
- */
134
- addPayment(params) {
135
- this.txns.push({ ...params, type: 'pay' });
136
- return this;
137
- }
138
- /**
139
- * Add an asset create transaction to the transaction group.
140
- * @param params The asset create transaction parameters
141
- * @returns The composer so you can chain method calls
142
- * @example Basic example
143
- * ```typescript
144
- * composer.addAssetCreate({ sender: "CREATORADDRESS", total: 100n})
145
- * ```
146
- * @example Advanced example
147
- * ```typescript
148
- * composer.addAssetCreate({
149
- * sender: 'CREATORADDRESS',
150
- * total: 100n,
151
- * decimals: 2,
152
- * assetName: 'asset',
153
- * unitName: 'unit',
154
- * url: 'url',
155
- * metadataHash: 'metadataHash',
156
- * defaultFrozen: false,
157
- * manager: 'MANAGERADDRESS',
158
- * reserve: 'RESERVEADDRESS',
159
- * freeze: 'FREEZEADDRESS',
160
- * clawback: 'CLAWBACKADDRESS',
161
- * lease: 'lease',
162
- * note: 'note',
163
- * // You wouldn't normally set this field
164
- * firstValidRound: 1000n,
165
- * validityWindow: 10,
166
- * extraFee: (1000).microAlgo(),
167
- * staticFee: (1000).microAlgo(),
168
- * // Max fee doesn't make sense with extraFee AND staticFee
169
- * // already specified, but here for completeness
170
- * maxFee: (3000).microAlgo(),
171
- * })
172
- */
173
- addAssetCreate(params) {
174
- this.txns.push({ ...params, type: 'assetCreate' });
175
- return this;
176
- }
177
- /**
178
- * Add an asset config transaction to the transaction group.
179
- * @param params The asset config transaction parameters
180
- * @returns The composer so you can chain method calls
181
- * @example Basic example
182
- * ```typescript
183
- * composer.addAssetConfig({ sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" })
184
- * ```
185
- * @example Advanced example
186
- * ```typescript
187
- * composer.addAssetConfig({
188
- * sender: 'MANAGERADDRESS',
189
- * assetId: 123456n,
190
- * manager: 'MANAGERADDRESS',
191
- * reserve: 'RESERVEADDRESS',
192
- * freeze: 'FREEZEADDRESS',
193
- * clawback: 'CLAWBACKADDRESS',
194
- * lease: 'lease',
195
- * note: 'note',
196
- * // You wouldn't normally set this field
197
- * firstValidRound: 1000n,
198
- * validityWindow: 10,
199
- * extraFee: (1000).microAlgo(),
200
- * staticFee: (1000).microAlgo(),
201
- * // Max fee doesn't make sense with extraFee AND staticFee
202
- * // already specified, but here for completeness
203
- * maxFee: (3000).microAlgo(),
204
- * })
205
- */
206
- addAssetConfig(params) {
207
- this.txns.push({ ...params, type: 'assetConfig' });
208
- return this;
209
- }
210
- /**
211
- * Add an asset freeze transaction to the transaction group.
212
- * @param params The asset freeze transaction parameters
213
- * @returns The composer so you can chain method calls
214
- * @example Basic example
215
- * ```typescript
216
- * composer.addAssetFreeze({ sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true })
217
- * ```
218
- * @example Advanced example
219
- * ```typescript
220
- * composer.addAssetFreeze({
221
- * sender: 'MANAGERADDRESS',
222
- * assetId: 123456n,
223
- * account: 'ACCOUNTADDRESS',
224
- * frozen: true,
225
- * lease: 'lease',
226
- * note: 'note',
227
- * // You wouldn't normally set this field
228
- * firstValidRound: 1000n,
229
- * validityWindow: 10,
230
- * extraFee: (1000).microAlgo(),
231
- * staticFee: (1000).microAlgo(),
232
- * // Max fee doesn't make sense with extraFee AND staticFee
233
- * // already specified, but here for completeness
234
- * maxFee: (3000).microAlgo(),
235
- * })
236
- * ```
237
- */
238
- addAssetFreeze(params) {
239
- this.txns.push({ ...params, type: 'assetFreeze' });
240
- return this;
241
- }
242
- /**
243
- * Add an asset destroy transaction to the transaction group.
244
- * @param params The asset destroy transaction parameters
245
- * @returns The composer so you can chain method calls
246
- * @example Basic example
247
- * ```typescript
248
- * composer.addAssetDestroy({ sender: "MANAGERADDRESS", assetId: 123456n })
249
- * ```
250
- * @example Advanced example
251
- * ```typescript
252
- * composer.addAssetDestroy({
253
- * sender: 'MANAGERADDRESS',
254
- * assetId: 123456n,
255
- * lease: 'lease',
256
- * note: 'note',
257
- * // You wouldn't normally set this field
258
- * firstValidRound: 1000n,
259
- * validityWindow: 10,
260
- * extraFee: (1000).microAlgo(),
261
- * staticFee: (1000).microAlgo(),
262
- * // Max fee doesn't make sense with extraFee AND staticFee
263
- * // already specified, but here for completeness
264
- * maxFee: (3000).microAlgo(),
265
- * })
266
- * ```
267
- */
268
- addAssetDestroy(params) {
269
- this.txns.push({ ...params, type: 'assetDestroy' });
270
- return this;
271
- }
272
- /**
273
- * Add an asset transfer transaction to the transaction group.
274
- * @param params The asset transfer transaction parameters
275
- * @returns The composer so you can chain method calls
276
- * @example Basic example
277
- * ```typescript
278
- * composer.addAssetTransfer({ sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" })
279
- * ```
280
- * @example Advanced example (with clawback)
281
- * ```typescript
282
- * composer.addAssetTransfer({
283
- * sender: 'CLAWBACKADDRESS',
284
- * assetId: 123456n,
285
- * amount: 1n,
286
- * receiver: 'RECEIVERADDRESS',
287
- * clawbackTarget: 'HOLDERADDRESS',
288
- * // This field needs to be used with caution
289
- * closeAssetTo: 'ADDRESSTOCLOSETO'
290
- * lease: 'lease',
291
- * note: 'note',
292
- * // You wouldn't normally set this field
293
- * firstValidRound: 1000n,
294
- * validityWindow: 10,
295
- * extraFee: (1000).microAlgo(),
296
- * staticFee: (1000).microAlgo(),
297
- * // Max fee doesn't make sense with extraFee AND staticFee
298
- * // already specified, but here for completeness
299
- * maxFee: (3000).microAlgo(),
300
- * })
301
- * ```
302
- */
303
- addAssetTransfer(params) {
304
- this.txns.push({ ...params, type: 'assetTransfer' });
305
- return this;
306
- }
307
- /**
308
- * Add an asset opt-in transaction to the transaction group.
309
- * @param params The asset opt-in transaction parameters
310
- * @returns The composer so you can chain method calls
311
- * @example Basic example
312
- * ```typescript
313
- * composer.addAssetOptIn({ sender: "SENDERADDRESS", assetId: 123456n })
314
- * ```
315
- * @example Advanced example
316
- * ```typescript
317
- * composer.addAssetOptIn({
318
- * sender: 'SENDERADDRESS',
319
- * assetId: 123456n,
320
- * lease: 'lease',
321
- * note: 'note',
322
- * // You wouldn't normally set this field
323
- * firstValidRound: 1000n,
324
- * validityWindow: 10,
325
- * extraFee: (1000).microAlgo(),
326
- * staticFee: (1000).microAlgo(),
327
- * // Max fee doesn't make sense with extraFee AND staticFee
328
- * // already specified, but here for completeness
329
- * maxFee: (3000).microAlgo(),
330
- * })
331
- * ```
332
- */
333
- addAssetOptIn(params) {
334
- this.txns.push({ ...params, type: 'assetOptIn' });
335
- return this;
336
- }
337
- /**
338
- * Add an asset opt-out transaction to the transaction group.
339
- * @param params The asset opt-out transaction parameters
340
- * @returns The composer so you can chain method calls
341
- * @example Basic example (without creator, will be retrieved from algod)
342
- * ```typescript
343
- * composer.addAssetOptOut({ sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true })
344
- * ```
345
- * @example Basic example (with creator)
346
- * ```typescript
347
- * composer.addAssetOptOut({ sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true })
348
- * ```
349
- * @example Advanced example
350
- * ```typescript
351
- * composer.addAssetOptOut({
352
- * sender: 'SENDERADDRESS',
353
- * assetId: 123456n,
354
- * creator: 'CREATORADDRESS',
355
- * ensureZeroBalance: true,
356
- * lease: 'lease',
357
- * note: 'note',
358
- * // You wouldn't normally set this field
359
- * firstValidRound: 1000n,
360
- * validityWindow: 10,
361
- * extraFee: (1000).microAlgo(),
362
- * staticFee: (1000).microAlgo(),
363
- * // Max fee doesn't make sense with extraFee AND staticFee
364
- * // already specified, but here for completeness
365
- * maxFee: (3000).microAlgo(),
366
- * })
367
- * ```
368
- */
369
- addAssetOptOut(params) {
370
- this.txns.push({ ...params, type: 'assetOptOut' });
371
- return this;
372
- }
373
- /**
374
- * Add an application create transaction to the transaction group.
375
- *
376
- * Note: we recommend using app clients to make it easier to make app calls.
377
- * @param params The application create transaction parameters
378
- * @returns The composer so you can chain method calls
379
- * @example Basic example
380
- * ```typescript
381
- * composer.addAppCreate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
382
- * ```
383
- * @example Advanced example
384
- * ```typescript
385
- * composer.addAppCreate({
386
- * sender: 'CREATORADDRESS',
387
- * approvalProgram: "TEALCODE",
388
- * clearStateProgram: "TEALCODE",
389
- * schema: {
390
- * globalInts: 1,
391
- * globalByteSlices: 2,
392
- * localInts: 3,
393
- * localByteSlices: 4
394
- * },
395
- * extraProgramPages: 1,
396
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
397
- * args: [new Uint8Array(1, 2, 3, 4)]
398
- * accountReferences: ["ACCOUNT_1"]
399
- * appReferences: [123n, 1234n]
400
- * assetReferences: [12345n]
401
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
402
- * accessReferences: [{ appId: 1234n }]
403
- * lease: 'lease',
404
- * note: 'note',
405
- * // You wouldn't normally set this field
406
- * firstValidRound: 1000n,
407
- * validityWindow: 10,
408
- * extraFee: (1000).microAlgo(),
409
- * staticFee: (1000).microAlgo(),
410
- * // Max fee doesn't make sense with extraFee AND staticFee
411
- * // already specified, but here for completeness
412
- * maxFee: (3000).microAlgo(),
413
- * rejectVersion: 1,
414
- * // Signer only needed if you want to provide one,
415
- * // generally you'd register it with AlgorandClient
416
- * // against the sender and not need to pass it in
417
- * signer: transactionSigner,
418
- * maxRoundsToWaitForConfirmation: 5,
419
- * suppressLog: true,
420
- *})
421
- * ```
422
- */
423
- addAppCreate(params) {
424
- this.txns.push({ ...params, type: 'appCall' });
425
- return this;
426
- }
427
- /**
428
- * Add an application update transaction to the transaction group.
429
- *
430
- * Note: we recommend using app clients to make it easier to make app calls.
431
- * @param params The application update transaction parameters
432
- * @returns The composer so you can chain method calls
433
- * @example Basic example
434
- * ```typescript
435
- * composer.addAppUpdate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
436
- * ```
437
- * @example Advanced example
438
- * ```typescript
439
- * composer.addAppUpdate({
440
- * sender: 'CREATORADDRESS',
441
- * approvalProgram: "TEALCODE",
442
- * clearStateProgram: "TEALCODE",
443
- * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
444
- * args: [new Uint8Array(1, 2, 3, 4)]
445
- * accountReferences: ["ACCOUNT_1"]
446
- * appReferences: [123n, 1234n]
447
- * assetReferences: [12345n]
448
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
449
- * accessReferences: [{ appId: 1234n }]
450
- * lease: 'lease',
451
- * note: 'note',
452
- * // You wouldn't normally set this field
453
- * firstValidRound: 1000n,
454
- * validityWindow: 10,
455
- * extraFee: (1000).microAlgo(),
456
- * staticFee: (1000).microAlgo(),
457
- * // Max fee doesn't make sense with extraFee AND staticFee
458
- * // already specified, but here for completeness
459
- * maxFee: (3000).microAlgo(),
460
- * rejectVersion: 1,
461
- *})
462
- * ```
463
- */
464
- addAppUpdate(params) {
465
- this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
466
- return this;
467
- }
468
- /**
469
- * Add an application delete transaction to the transaction group.
470
- *
471
- * Note: we recommend using app clients to make it easier to make app calls.
472
- * @param params The application delete transaction parameters
473
- * @returns The composer so you can chain method calls
474
- * @example Basic example
475
- * ```typescript
476
- * composer.addAppDelete({ sender: 'CREATORADDRESS' })
477
- * ```
478
- * @example Advanced example
479
- * ```typescript
480
- * composer.addAppDelete({
481
- * sender: 'CREATORADDRESS',
482
- * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
483
- * args: [new Uint8Array(1, 2, 3, 4)]
484
- * accountReferences: ["ACCOUNT_1"]
485
- * appReferences: [123n, 1234n]
486
- * assetReferences: [12345n]
487
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
488
- * accessReferences: [{ appId: 1234n }]
489
- * lease: 'lease',
490
- * note: 'note',
491
- * // You wouldn't normally set this field
492
- * firstValidRound: 1000n,
493
- * validityWindow: 10,
494
- * extraFee: (1000).microAlgo(),
495
- * staticFee: (1000).microAlgo(),
496
- * // Max fee doesn't make sense with extraFee AND staticFee
497
- * // already specified, but here for completeness
498
- * maxFee: (3000).microAlgo(),
499
- * rejectVersion: 1,
500
- *})
501
- * ```
502
- */
503
- addAppDelete(params) {
504
- this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
505
- return this;
506
- }
507
- /**
508
- * Add an application call transaction to the transaction group.
509
- *
510
- * If you want to create or update an app use `addAppCreate` or `addAppUpdate`.
511
- *
512
- * Note: we recommend using app clients to make it easier to make app calls.
513
- * @param params The application call transaction parameters
514
- * @returns The composer so you can chain method calls
515
- * @example Basic example
516
- * ```typescript
517
- * composer.addAppCall({ sender: 'CREATORADDRESS' })
518
- * ```
519
- * @example Advanced example
520
- * ```typescript
521
- * composer.addAppCall({
522
- * sender: 'CREATORADDRESS',
523
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
524
- * args: [new Uint8Array(1, 2, 3, 4)]
525
- * accountReferences: ["ACCOUNT_1"]
526
- * appReferences: [123n, 1234n]
527
- * assetReferences: [12345n]
528
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
529
- * accessReferences: [{ appId: 1234n }]
530
- * lease: 'lease',
531
- * note: 'note',
532
- * // You wouldn't normally set this field
533
- * firstValidRound: 1000n,
534
- * validityWindow: 10,
535
- * extraFee: (1000).microAlgo(),
536
- * staticFee: (1000).microAlgo(),
537
- * // Max fee doesn't make sense with extraFee AND staticFee
538
- * // already specified, but here for completeness
539
- * maxFee: (3000).microAlgo(),
540
- * rejectVersion: 1,
541
- *})
542
- * ```
543
- */
544
- addAppCall(params) {
545
- this.txns.push({ ...params, type: 'appCall' });
546
- return this;
547
- }
548
- /**
549
- * Add an ABI method create application call transaction to the transaction group.
550
- *
551
- * Note: we recommend using app clients to make it easier to make app calls.
552
- * @param params The ABI create method application call transaction parameters
553
- * @returns The composer so you can chain method calls
554
- * @example Basic example
555
- * ```typescript
556
- * const method = new ABIMethod({
557
- * name: 'method',
558
- * args: [{ name: 'arg1', type: 'string' }],
559
- * returns: { type: 'string' },
560
- * })
561
- * composer.addAppCreateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
562
- * ```
563
- * @example Advanced example
564
- * ```typescript
565
- * const method = new ABIMethod({
566
- * name: 'method',
567
- * args: [{ name: 'arg1', type: 'string' }],
568
- * returns: { type: 'string' },
569
- * })
570
- * composer.addAppCreateMethodCall({
571
- * sender: 'CREATORADDRESS',
572
- * method: method,
573
- * args: ["arg1_value"],
574
- * approvalProgram: "TEALCODE",
575
- * clearStateProgram: "TEALCODE",
576
- * schema: {
577
- * globalInts: 1,
578
- * globalByteSlices: 2,
579
- * localInts: 3,
580
- * localByteSlices: 4
581
- * },
582
- * extraProgramPages: 1,
583
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
584
- * args: [new Uint8Array(1, 2, 3, 4)]
585
- * accountReferences: ["ACCOUNT_1"]
586
- * appReferences: [123n, 1234n]
587
- * assetReferences: [12345n]
588
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
589
- * accessReferences: [{ appId: 1234n }]
590
- * lease: 'lease',
591
- * note: 'note',
592
- * // You wouldn't normally set this field
593
- * firstValidRound: 1000n,
594
- * validityWindow: 10,
595
- * extraFee: (1000).microAlgo(),
596
- * staticFee: (1000).microAlgo(),
597
- * // Max fee doesn't make sense with extraFee AND staticFee
598
- * // already specified, but here for completeness
599
- * maxFee: (3000).microAlgo(),
600
- * rejectVersion: 1,
601
- *})
602
- * ```
603
- */
604
- addAppCreateMethodCall(params) {
605
- this.txns.push({ ...params, type: 'methodCall' });
606
- return this;
607
- }
608
- /**
609
- * Add an ABI method update application call transaction to the transaction group.
610
- *
611
- * Note: we recommend using app clients to make it easier to make app calls.
612
- * @param params The ABI update method application call transaction parameters
613
- * @returns The composer so you can chain method calls
614
- * @example Basic example
615
- * ```typescript
616
- * const method = new ABIMethod({
617
- * name: 'method',
618
- * args: [{ name: 'arg1', type: 'string' }],
619
- * returns: { type: 'string' },
620
- * })
621
- * composer.addAppUpdateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
622
- * ```
623
- * @example Advanced example
624
- * ```typescript
625
- * const method = new ABIMethod({
626
- * name: 'method',
627
- * args: [{ name: 'arg1', type: 'string' }],
628
- * returns: { type: 'string' },
629
- * })
630
- * composer.addAppUpdateMethodCall({
631
- * sender: 'CREATORADDRESS',
632
- * method: method,
633
- * args: ["arg1_value"],
634
- * approvalProgram: "TEALCODE",
635
- * clearStateProgram: "TEALCODE",
636
- * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
637
- * args: [new Uint8Array(1, 2, 3, 4)]
638
- * accountReferences: ["ACCOUNT_1"]
639
- * appReferences: [123n, 1234n]
640
- * assetReferences: [12345n]
641
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
642
- * accessReferences: [{ appId: 1234n }]
643
- * lease: 'lease',
644
- * note: 'note',
645
- * // You wouldn't normally set this field
646
- * firstValidRound: 1000n,
647
- * validityWindow: 10,
648
- * extraFee: (1000).microAlgo(),
649
- * staticFee: (1000).microAlgo(),
650
- * // Max fee doesn't make sense with extraFee AND staticFee
651
- * // already specified, but here for completeness
652
- * maxFee: (3000).microAlgo(),
653
- * rejectVersion: 1,
654
- *})
655
- * ```
656
- */
657
- addAppUpdateMethodCall(params) {
658
- this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
659
- return this;
660
- }
661
- /**
662
- * Add an ABI method delete application call transaction to the transaction group.
663
- *
664
- * Note: we recommend using app clients to make it easier to make app calls.
665
- * @param params The ABI delete method application call transaction parameters
666
- * @returns The composer so you can chain method calls
667
- * @example Basic example
668
- * ```typescript
669
- * const method = new ABIMethod({
670
- * name: 'method',
671
- * args: [{ name: 'arg1', type: 'string' }],
672
- * returns: { type: 'string' },
673
- * })
674
- * composer.addAppDeleteMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
675
- * ```
676
- * @example Advanced example
677
- * ```typescript
678
- * const method = new ABIMethod({
679
- * name: 'method',
680
- * args: [{ name: 'arg1', type: 'string' }],
681
- * returns: { type: 'string' },
682
- * })
683
- * composer.addAppDeleteMethodCall({
684
- * sender: 'CREATORADDRESS',
685
- * method: method,
686
- * args: ["arg1_value"],
687
- * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
688
- * args: [new Uint8Array(1, 2, 3, 4)]
689
- * accountReferences: ["ACCOUNT_1"]
690
- * appReferences: [123n, 1234n]
691
- * assetReferences: [12345n]
692
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
693
- * accessReferences: [{ appId: 1234n }]
694
- * lease: 'lease',
695
- * note: 'note',
696
- * // You wouldn't normally set this field
697
- * firstValidRound: 1000n,
698
- * validityWindow: 10,
699
- * extraFee: (1000).microAlgo(),
700
- * staticFee: (1000).microAlgo(),
701
- * // Max fee doesn't make sense with extraFee AND staticFee
702
- * // already specified, but here for completeness
703
- * maxFee: (3000).microAlgo(),
704
- * rejectVersion: 1,
705
- *})
706
- * ```
707
- */
708
- addAppDeleteMethodCall(params) {
709
- this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
710
- return this;
711
- }
712
- /**
713
- * Add a non-create/non-update ABI method application call transaction to the transaction group.
714
- *
715
- * Note: we recommend using app clients to make it easier to make app calls.
716
- * @param params The ABI method application call transaction parameters
717
- * @returns The composer so you can chain method calls
718
- * @example Basic example
719
- * ```typescript
720
- * const method = new ABIMethod({
721
- * name: 'method',
722
- * args: [{ name: 'arg1', type: 'string' }],
723
- * returns: { type: 'string' },
724
- * })
725
- * composer.addAppCallMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
726
- * ```
727
- * @example Advanced example
728
- * ```typescript
729
- * const method = new ABIMethod({
730
- * name: 'method',
731
- * args: [{ name: 'arg1', type: 'string' }],
732
- * returns: { type: 'string' },
733
- * })
734
- * composer.addAppCallMethodCall({
735
- * sender: 'CREATORADDRESS',
736
- * method: method,
737
- * args: ["arg1_value"],
738
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
739
- * args: [new Uint8Array(1, 2, 3, 4)]
740
- * accountReferences: ["ACCOUNT_1"]
741
- * appReferences: [123n, 1234n]
742
- * assetReferences: [12345n]
743
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
744
- * accessReferences: [{ appId: 1234n }]
745
- * lease: 'lease',
746
- * note: 'note',
747
- * // You wouldn't normally set this field
748
- * firstValidRound: 1000n,
749
- * validityWindow: 10,
750
- * extraFee: (1000).microAlgo(),
751
- * staticFee: (1000).microAlgo(),
752
- * // Max fee doesn't make sense with extraFee AND staticFee
753
- * // already specified, but here for completeness
754
- * maxFee: (3000).microAlgo(),
755
- * rejectVersion: 1,
756
- *})
757
- * ```
758
- */
759
- addAppCallMethodCall(params) {
760
- this.txns.push({ ...params, type: 'methodCall' });
761
- return this;
762
- }
763
- /**
764
- * Add an online key registration transaction to the transaction group.
765
- * @param params The online key registration transaction parameters
766
- * @returns The composer so you can chain method calls
767
- * @example Basic example
768
- * ```typescript
769
- * composer.addOnlineKeyRegistration({
770
- * sender: 'SENDERADDRESS',
771
- * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
772
- * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
773
- * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
774
- * voteFirst: 1n,
775
- * voteLast: 1000n,
776
- * voteKeyDilution: 1n,
777
- * })
778
- * ```
779
- * @example Advanced example
780
- * ```typescript
781
- * composer.addOnlineKeyRegistration({
782
- * sender: 'SENDERADDRESS',
783
- * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
784
- * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
785
- * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
786
- * voteFirst: 1n,
787
- * voteLast: 1000n,
788
- * voteKeyDilution: 1n,
789
- * lease: 'lease',
790
- * note: 'note',
791
- * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
792
- * rekeyTo: 'REKEYTOADDRESS',
793
- * // You wouldn't normally set this field
794
- * firstValidRound: 1000n,
795
- * validityWindow: 10,
796
- * extraFee: (1000).microAlgo(),
797
- * staticFee: (1000).microAlgo(),
798
- * // Max fee doesn't make sense with extraFee AND staticFee
799
- * // already specified, but here for completeness
800
- * maxFee: (3000).microAlgo(),
801
- * })
802
- * ```
803
- */
804
- addOnlineKeyRegistration(params) {
805
- this.txns.push({ ...params, type: 'keyReg' });
806
- return this;
807
- }
808
- /**
809
- * Add an offline key registration transaction to the transaction group.
810
- * @param params The offline key registration transaction parameters
811
- * @returns The composer so you can chain method calls
812
- * @example Basic example
813
- * ```typescript
814
- * composer.addOfflineKeyRegistration({
815
- * sender: 'SENDERADDRESS',
816
- * })
817
- * ```
818
- * @example Advanced example
819
- * ```typescript
820
- * composer.addOfflineKeyRegistration({
821
- * sender: 'SENDERADDRESS',
822
- * lease: 'lease',
823
- * note: 'note',
824
- * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
825
- * rekeyTo: 'REKEYTOADDRESS',
826
- * // You wouldn't normally set this field
827
- * firstValidRound: 1000n,
828
- * validityWindow: 10,
829
- * extraFee: (1000).microAlgo(),
830
- * staticFee: (1000).microAlgo(),
831
- * // Max fee doesn't make sense with extraFee AND staticFee
832
- * // already specified, but here for completeness
833
- * maxFee: (3000).microAlgo(),
834
- * })
835
- * ```
836
- */
837
- addOfflineKeyRegistration(params) {
838
- this.txns.push({ ...params, type: 'keyReg' });
839
- return this;
840
- }
841
- /**
842
- * Add the transactions within an `AtomicTransactionComposer` to the transaction group.
843
- * @param atc The `AtomicTransactionComposer` to build transactions from and add to the group
844
- * @returns The composer so you can chain method calls
845
- * @example
846
- * ```typescript
847
- * const atc = new AtomicTransactionComposer()
848
- * .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: 1000n })
849
- * composer.addAtc(atc)
850
- * ```
851
- */
852
- addAtc(atc) {
853
- this.txns.push({ atc, type: 'atc' });
854
- return this;
855
- }
856
- /** Build an ATC and return transactions ready to be incorporated into a broader set of transactions this composer is composing */
857
- buildAtc(atc) {
858
- const group = atc.buildGroup();
859
- const txnWithSigners = group.map((ts, idx) => {
860
- // Remove underlying group ID from the transaction since it will be re-grouped when this TransactionComposer is built
861
- ts.txn.group = undefined;
862
- // If this was a method call return the ABIMethod for later
863
- if (atc['methodCalls'].get(idx)) {
864
- return {
865
- ...ts,
866
- context: { abiMethod: atc['methodCalls'].get(idx) },
867
- };
868
- }
869
- return {
870
- ...ts,
871
- context: {},
872
- };
873
- });
874
- return txnWithSigners;
875
- }
876
- commonTxnBuildStep(buildTxn, params, txnParams) {
877
- // We are going to mutate suggested params, let's create a clone first
878
- txnParams.suggestedParams = { ...txnParams.suggestedParams };
879
- if (params.lease)
880
- txnParams.lease = encodeLease(params.lease);
881
- if (params.rekeyTo)
882
- txnParams.rekeyTo = address(params.rekeyTo);
883
- const encoder = new TextEncoder();
884
- if (params.note)
885
- txnParams.note = (typeof params.note === 'string' ? encoder.encode(params.note) : params.note);
886
- if (params.firstValidRound) {
887
- txnParams.suggestedParams.firstValid = params.firstValidRound;
888
- }
889
- if (params.lastValidRound) {
890
- txnParams.suggestedParams.lastValid = params.lastValidRound;
891
- }
892
- else {
893
- // If the validity window isn't set in this transaction or by default and we are pointing at
894
- // LocalNet set a bigger window to avoid dead transactions
895
- const window = params.validityWindow
896
- ? BigInt(params.validityWindow)
897
- : !this.defaultValidityWindowIsExplicit && genesisIdIsLocalNet(txnParams.suggestedParams.genesisID ?? 'unknown')
898
- ? 1000n
899
- : this.defaultValidityWindow;
900
- txnParams.suggestedParams.lastValid = BigInt(txnParams.suggestedParams.firstValid) + window;
901
- }
902
- if (params.staticFee !== undefined && params.extraFee !== undefined) {
903
- throw Error('Cannot set both staticFee and extraFee');
904
- }
905
- if (params.staticFee !== undefined) {
906
- txnParams.suggestedParams.fee = params.staticFee.microAlgo;
907
- txnParams.suggestedParams.flatFee = true;
908
- }
909
- const txn = buildTxn(txnParams);
910
- if (params.extraFee)
911
- txn.fee += params.extraFee.microAlgo;
912
- if (params.maxFee !== undefined && txn.fee > params.maxFee.microAlgo) {
913
- throw Error(`Transaction fee ${txn.fee} µALGO is greater than maxFee ${params.maxFee}`);
914
- }
915
- const logicalMaxFee = params.maxFee !== undefined && params.maxFee.microAlgo > (params.staticFee?.microAlgo ?? 0n) ? params.maxFee : params.staticFee;
916
- return { txn, context: { maxFee: logicalMaxFee } };
917
- }
918
- /**
919
- * Builds an ABI method call transaction and any other associated transactions represented in the ABI args.
920
- * @param includeSigner Whether to include the actual signer for the transactions.
921
- * If you are just building transactions without signers yet then set this to `false`.
922
- */
923
- async buildMethodCall(params, suggestedParams, includeSigner) {
924
- const methodArgs = [];
925
- const transactionsForGroup = [];
926
- const isAbiValue = (x) => {
927
- if (Array.isArray(x))
928
- return x.length == 0 || x.every(isAbiValue);
929
- return (typeof x === 'bigint' ||
930
- typeof x === 'boolean' ||
931
- typeof x === 'number' ||
932
- typeof x === 'string' ||
933
- x instanceof Uint8Array ||
934
- x instanceof algosdk.Address);
935
- };
936
- for (let i = (params.args ?? []).length - 1; i >= 0; i--) {
937
- const arg = params.args[i];
938
- if (arg === undefined) {
939
- // An undefined transaction argument signals that the value will be supplied by a method call argument
940
- if (algosdk.abiTypeIsTransaction(params.method.args[i].type) && transactionsForGroup.length > 0) {
941
- // Move the last transaction from the group to the method call arguments to appease algosdk
942
- const placeholderTransaction = transactionsForGroup.splice(-1, 1)[0];
943
- methodArgs.push(placeholderTransaction);
944
- continue;
945
- }
946
- throw Error(`No value provided for argument ${i + 1} within call to ${params.method.name}`);
947
- }
948
- if (isAbiValue(arg)) {
949
- methodArgs.push(arg);
950
- continue;
951
- }
952
- if (isTransactionWithSigner(arg)) {
953
- methodArgs.push(arg);
954
- continue;
955
- }
956
- if ('method' in arg) {
957
- const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams, includeSigner);
958
- // If there is any transaction args, add to the atc
959
- // Everything else should be added as method args
960
- methodArgs.push(...tempTxnWithSigners.slice(-1)); // Add the method call itself as a method arg
961
- transactionsForGroup.push(...tempTxnWithSigners.slice(0, -1).reverse()); // Add any transaction arguments to the atc
962
- continue;
963
- }
964
- const txn = await arg;
965
- methodArgs.push({
966
- txn,
967
- signer: includeSigner
968
- ? params.signer
969
- ? 'signer' in params.signer
970
- ? params.signer.signer
971
- : params.signer
972
- : this.getSigner(txn.sender)
973
- : TransactionComposer.NULL_SIGNER,
974
- });
975
- }
976
- const methodAtc = new algosdk.AtomicTransactionComposer();
977
- const maxFees = new Map();
978
- transactionsForGroup.reverse().forEach(({ context, ...txnWithSigner }) => {
979
- methodAtc.addTransaction(txnWithSigner);
980
- const atcIndex = methodAtc.count() - 1;
981
- if (context.abiMethod) {
982
- methodAtc['methodCalls'].set(atcIndex, context.abiMethod);
983
- }
984
- if (context.maxFee !== undefined) {
985
- maxFees.set(atcIndex, context.maxFee);
986
- }
987
- });
988
- // If any of the args are method call transactions, add that info to the methodAtc
989
- methodArgs
990
- .filter((arg) => {
991
- if (typeof arg === 'object' && 'context' in arg) {
992
- const { context, ...txnWithSigner } = arg;
993
- return isTransactionWithSigner(txnWithSigner);
994
- }
995
- return isTransactionWithSigner(arg);
996
- })
997
- .reverse()
998
- .forEach((arg, idx) => {
999
- if (typeof arg === 'object' && 'context' in arg && arg.context) {
1000
- const atcIndex = methodAtc.count() + idx;
1001
- if (arg.context.abiMethod) {
1002
- methodAtc['methodCalls'].set(atcIndex, arg.context.abiMethod);
1003
- }
1004
- if (arg.context.maxFee !== undefined) {
1005
- maxFees.set(atcIndex, arg.context.maxFee);
1006
- }
1007
- }
1008
- });
1009
- const appId = Number('appId' in params ? params.appId : 0n);
1010
- const approvalProgram = 'approvalProgram' in params
1011
- ? typeof params.approvalProgram === 'string'
1012
- ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
1013
- : params.approvalProgram
1014
- : undefined;
1015
- const clearStateProgram = 'clearStateProgram' in params
1016
- ? typeof params.clearStateProgram === 'string'
1017
- ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
1018
- : params.clearStateProgram
1019
- : undefined;
1020
- const txnParams = {
1021
- appID: appId,
1022
- sender: params.sender,
1023
- suggestedParams,
1024
- onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
1025
- appAccounts: params.accountReferences,
1026
- appForeignApps: params.appReferences?.map((x) => Number(x)),
1027
- appForeignAssets: params.assetReferences?.map((x) => Number(x)),
1028
- boxes: params.boxReferences?.map(AppManager.getBoxReference),
1029
- access: params.accessReferences?.map(getResourceReference),
1030
- approvalProgram,
1031
- clearProgram: clearStateProgram,
1032
- extraPages: appId === 0
1033
- ? 'extraProgramPages' in params && params.extraProgramPages !== undefined
1034
- ? params.extraProgramPages
1035
- : approvalProgram
1036
- ? calculateExtraProgramPages(approvalProgram, clearStateProgram)
1037
- : 0
1038
- : undefined,
1039
- numLocalInts: appId === 0 ? ('schema' in params ? (params.schema?.localInts ?? 0) : 0) : undefined,
1040
- numLocalByteSlices: appId === 0 ? ('schema' in params ? (params.schema?.localByteSlices ?? 0) : 0) : undefined,
1041
- numGlobalInts: appId === 0 ? ('schema' in params ? (params.schema?.globalInts ?? 0) : 0) : undefined,
1042
- numGlobalByteSlices: appId === 0 ? ('schema' in params ? (params.schema?.globalByteSlices ?? 0) : 0) : undefined,
1043
- method: params.method,
1044
- signer: includeSigner
1045
- ? params.signer
1046
- ? 'signer' in params.signer
1047
- ? params.signer.signer
1048
- : params.signer
1049
- : this.getSigner(params.sender)
1050
- : TransactionComposer.NULL_SIGNER,
1051
- methodArgs: methodArgs
1052
- .map((arg) => {
1053
- if (typeof arg === 'object' && 'context' in arg) {
1054
- const { context, ...txnWithSigner } = arg;
1055
- return txnWithSigner;
1056
- }
1057
- return arg;
1058
- })
1059
- .reverse(),
1060
- rejectVersion: params.rejectVersion,
1061
- // note, lease, and rekeyTo are set in the common build step
1062
- note: undefined,
1063
- lease: undefined,
1064
- rekeyTo: undefined,
1065
- };
1066
- // Build the transaction
1067
- const result = this.commonTxnBuildStep((txnParams) => {
1068
- methodAtc.addMethodCall(txnParams);
1069
- return methodAtc.buildGroup()[methodAtc.count() - 1].txn;
1070
- }, params, txnParams);
1071
- // Process the ATC to get a set of transactions ready for broader grouping
1072
- return this.buildAtc(methodAtc).map(({ context: _context, ...txnWithSigner }, idx) => {
1073
- const maxFee = idx === methodAtc.count() - 1 ? result.context.maxFee : maxFees.get(idx);
1074
- const context = {
1075
- ..._context, // Adds method context info
1076
- maxFee,
1077
- };
1078
- return {
1079
- ...txnWithSigner,
1080
- context,
1081
- };
1082
- });
1083
- }
1084
- buildPayment(params, suggestedParams) {
1085
- return this.commonTxnBuildStep(algosdk.makePaymentTxnWithSuggestedParamsFromObject, params, {
1086
- sender: params.sender,
1087
- receiver: params.receiver,
1088
- amount: params.amount.microAlgo,
1089
- closeRemainderTo: params.closeRemainderTo,
1090
- suggestedParams,
1091
- });
1092
- }
1093
- buildAssetCreate(params, suggestedParams) {
1094
- return this.commonTxnBuildStep(algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject, params, {
1095
- sender: params.sender,
1096
- total: params.total,
1097
- decimals: params.decimals ?? 0,
1098
- assetName: params.assetName,
1099
- unitName: params.unitName,
1100
- assetURL: params.url,
1101
- defaultFrozen: params.defaultFrozen ?? false,
1102
- assetMetadataHash: typeof params.metadataHash === 'string' ? Buffer.from(params.metadataHash, 'utf-8') : params.metadataHash,
1103
- manager: params.manager,
1104
- reserve: params.reserve,
1105
- freeze: params.freeze,
1106
- clawback: params.clawback,
1107
- suggestedParams,
1108
- });
1109
- }
1110
- buildAssetConfig(params, suggestedParams) {
1111
- return this.commonTxnBuildStep(algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject, params, {
1112
- sender: params.sender,
1113
- assetIndex: params.assetId,
1114
- suggestedParams,
1115
- manager: params.manager,
1116
- reserve: params.reserve,
1117
- freeze: params.freeze,
1118
- clawback: params.clawback,
1119
- strictEmptyAddressChecking: false,
1120
- });
1121
- }
1122
- buildAssetDestroy(params, suggestedParams) {
1123
- return this.commonTxnBuildStep(algosdk.makeAssetDestroyTxnWithSuggestedParamsFromObject, params, {
1124
- sender: params.sender,
1125
- assetIndex: params.assetId,
1126
- suggestedParams,
1127
- });
1128
- }
1129
- buildAssetFreeze(params, suggestedParams) {
1130
- return this.commonTxnBuildStep(algosdk.makeAssetFreezeTxnWithSuggestedParamsFromObject, params, {
1131
- sender: params.sender,
1132
- assetIndex: params.assetId,
1133
- freezeTarget: params.account,
1134
- frozen: params.frozen,
1135
- suggestedParams,
1136
- });
1137
- }
1138
- buildAssetTransfer(params, suggestedParams) {
1139
- return this.commonTxnBuildStep(algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject, params, {
1140
- sender: params.sender,
1141
- receiver: params.receiver,
1142
- assetIndex: params.assetId,
1143
- amount: params.amount,
1144
- suggestedParams,
1145
- closeRemainderTo: params.closeAssetTo,
1146
- assetSender: params.clawbackTarget,
1147
- });
1148
- }
1149
- async buildAppCall(params, suggestedParams) {
1150
- const appId = 'appId' in params ? params.appId : 0n;
1151
- const approvalProgram = 'approvalProgram' in params
1152
- ? typeof params.approvalProgram === 'string'
1153
- ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
1154
- : params.approvalProgram
1155
- : undefined;
1156
- const clearStateProgram = 'clearStateProgram' in params
1157
- ? typeof params.clearStateProgram === 'string'
1158
- ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
1159
- : params.clearStateProgram
1160
- : undefined;
1161
- const sdkParams = {
1162
- sender: params.sender,
1163
- suggestedParams,
1164
- appArgs: params.args,
1165
- onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
1166
- accounts: params.accountReferences,
1167
- foreignApps: params.appReferences?.map((x) => Number(x)),
1168
- foreignAssets: params.assetReferences?.map((x) => Number(x)),
1169
- boxes: params.boxReferences?.map(AppManager.getBoxReference),
1170
- access: params.accessReferences?.map(getResourceReference),
1171
- approvalProgram,
1172
- clearProgram: clearStateProgram,
1173
- rejectVersion: params.rejectVersion,
1174
- };
1175
- if (appId === 0n) {
1176
- if (sdkParams.approvalProgram === undefined || sdkParams.clearProgram === undefined) {
1177
- throw new Error('approvalProgram and clearStateProgram are required for application creation');
1178
- }
1179
- return this.commonTxnBuildStep(algosdk.makeApplicationCreateTxnFromObject, params, {
1180
- ...sdkParams,
1181
- extraPages: 'extraProgramPages' in params && params.extraProgramPages !== undefined
1182
- ? params.extraProgramPages
1183
- : calculateExtraProgramPages(approvalProgram, clearStateProgram),
1184
- numLocalInts: 'schema' in params ? (params.schema?.localInts ?? 0) : 0,
1185
- numLocalByteSlices: 'schema' in params ? (params.schema?.localByteSlices ?? 0) : 0,
1186
- numGlobalInts: 'schema' in params ? (params.schema?.globalInts ?? 0) : 0,
1187
- numGlobalByteSlices: 'schema' in params ? (params.schema?.globalByteSlices ?? 0) : 0,
1188
- approvalProgram: approvalProgram,
1189
- clearProgram: clearStateProgram,
1190
- });
1191
- }
1192
- else {
1193
- return this.commonTxnBuildStep(algosdk.makeApplicationCallTxnFromObject, params, { ...sdkParams, appIndex: appId });
1194
- }
1195
- }
1196
- buildKeyReg(params, suggestedParams) {
1197
- if ('voteKey' in params) {
1198
- return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1199
- sender: params.sender,
1200
- voteKey: params.voteKey,
1201
- selectionKey: params.selectionKey,
1202
- voteFirst: params.voteFirst,
1203
- voteLast: params.voteLast,
1204
- voteKeyDilution: params.voteKeyDilution,
1205
- suggestedParams,
1206
- nonParticipation: false,
1207
- stateProofKey: params.stateProofKey,
1208
- });
1209
- }
1210
- return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1211
- sender: params.sender,
1212
- suggestedParams,
1213
- nonParticipation: params.preventAccountFromEverParticipatingAgain,
1214
- });
1215
- }
1216
- /** Builds all transaction types apart from `txnWithSigner`, `atc` and `methodCall` since those ones can have custom signers that need to be retrieved. */
1217
- async buildTxn(txn, suggestedParams) {
1218
- switch (txn.type) {
1219
- case 'pay':
1220
- return [this.buildPayment(txn, suggestedParams)];
1221
- case 'assetCreate':
1222
- return [this.buildAssetCreate(txn, suggestedParams)];
1223
- case 'appCall':
1224
- return [await this.buildAppCall(txn, suggestedParams)];
1225
- case 'assetConfig':
1226
- return [this.buildAssetConfig(txn, suggestedParams)];
1227
- case 'assetDestroy':
1228
- return [this.buildAssetDestroy(txn, suggestedParams)];
1229
- case 'assetFreeze':
1230
- return [this.buildAssetFreeze(txn, suggestedParams)];
1231
- case 'assetTransfer':
1232
- return [this.buildAssetTransfer(txn, suggestedParams)];
1233
- case 'assetOptIn':
1234
- return [this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n }, suggestedParams)];
1235
- case 'assetOptOut':
1236
- return [this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n, closeAssetTo: txn.creator }, suggestedParams)];
1237
- case 'keyReg':
1238
- return [this.buildKeyReg(txn, suggestedParams)];
1239
- default:
1240
- throw Error(`Unsupported txn type`);
1241
- }
1242
- }
1243
- async buildTxnWithSigner(txn, suggestedParams) {
1244
- if (txn.type === 'txnWithSigner') {
1245
- return [
1246
- {
1247
- ...txn,
1248
- context: {},
1249
- },
1250
- ];
1251
- }
1252
- if (txn.type === 'atc') {
1253
- return this.buildAtc(txn.atc);
1254
- }
1255
- if (txn.type === 'methodCall') {
1256
- return await this.buildMethodCall(txn, suggestedParams, true);
1257
- }
1258
- const signer = txn.signer ? ('signer' in txn.signer ? txn.signer.signer : txn.signer) : this.getSigner(txn.sender);
1259
- return (await this.buildTxn(txn, suggestedParams)).map(({ txn, context }) => ({ txn, signer, context }));
1260
- }
1261
- /**
1262
- * Compose all of the transactions without signers and return the transaction objects directly along with any ABI method calls.
1263
- *
1264
- * @returns The array of built transactions and any corresponding method calls
1265
- * @example
1266
- * ```typescript
1267
- * const { transactions, methodCalls, signers } = await composer.buildTransactions()
1268
- * ```
1269
- */
1270
- async buildTransactions() {
1271
- const suggestedParams = await this.getSuggestedParams();
1272
- const transactions = [];
1273
- const methodCalls = new Map();
1274
- const signers = new Map();
1275
- for (const txn of this.txns) {
1276
- if (!['txnWithSigner', 'atc', 'methodCall'].includes(txn.type)) {
1277
- transactions.push(...(await this.buildTxn(txn, suggestedParams)).map((txn) => txn.txn));
1278
- }
1279
- else {
1280
- const transactionsWithSigner = txn.type === 'txnWithSigner'
1281
- ? [txn]
1282
- : txn.type === 'atc'
1283
- ? this.buildAtc(txn.atc)
1284
- : txn.type === 'methodCall'
1285
- ? await this.buildMethodCall(txn, suggestedParams, false)
1286
- : [];
1287
- transactionsWithSigner.forEach((ts) => {
1288
- transactions.push(ts.txn);
1289
- const groupIdx = transactions.length - 1;
1290
- if (ts.signer && ts.signer !== TransactionComposer.NULL_SIGNER) {
1291
- signers.set(groupIdx, ts.signer);
1292
- }
1293
- if ('context' in ts && ts.context.abiMethod) {
1294
- methodCalls.set(groupIdx, ts.context.abiMethod);
1295
- }
1296
- });
1297
- }
1298
- }
1299
- return { transactions, methodCalls, signers };
1300
- }
1301
- /**
1302
- * Get the number of transactions currently added to this composer.
1303
- * @returns The number of transactions currently added to this composer
1304
- */
1305
- async count() {
1306
- return (await this.buildTransactions()).transactions.length;
1307
- }
1308
- /**
1309
- * Compose all of the transactions in a single atomic transaction group and an atomic transaction composer.
1310
- *
1311
- * You can then use the transactions standalone, or use the composer to execute or simulate the transactions.
1312
- *
1313
- * Once this method is called, no further transactions will be able to be added.
1314
- * You can safely call this method multiple times to get the same result.
1315
- * @returns The built atomic transaction composer, the transactions and any corresponding method calls
1316
- * @example
1317
- * ```typescript
1318
- * const { atc, transactions, methodCalls } = await composer.build()
1319
- * ```
1320
- */
1321
- async build() {
1322
- if (this.atc.getStatus() === algosdk.AtomicTransactionComposerStatus.BUILDING) {
1323
- const suggestedParams = await this.getSuggestedParams();
1324
- // Build all of the transactions
1325
- const txnWithSigners = [];
1326
- for (const txn of this.txns) {
1327
- txnWithSigners.push(...(await this.buildTxnWithSigner(txn, suggestedParams)));
1328
- }
1329
- // Add all of the transactions to the underlying ATC
1330
- const methodCalls = new Map();
1331
- txnWithSigners.forEach(({ context, ...ts }, idx) => {
1332
- this.atc.addTransaction(ts);
1333
- // Populate consolidated set of all ABI method calls
1334
- if (context.abiMethod) {
1335
- methodCalls.set(idx, context.abiMethod);
1336
- }
1337
- if (context.maxFee !== undefined) {
1338
- this.txnMaxFees.set(idx, context.maxFee);
1339
- }
1340
- });
1341
- this.atc['methodCalls'] = methodCalls;
1342
- }
1343
- const transactions = this.atc.buildGroup();
1344
- return { atc: this.atc, transactions, methodCalls: this.atc['methodCalls'] };
1345
- }
1346
- /**
1347
- * Rebuild the group, discarding any previously built transactions.
1348
- * This will potentially cause new signers and suggested params to be used if the callbacks return a new value compared to the first build.
1349
- * @returns The newly built atomic transaction composer and the transactions
1350
- * @example
1351
- * ```typescript
1352
- * const { atc, transactions, methodCalls } = await composer.rebuild()
1353
- * ```
1354
- */
1355
- async rebuild() {
1356
- this.atc = new algosdk.AtomicTransactionComposer();
1357
- return await this.build();
1358
- }
1359
- /**
1360
- * Compose the atomic transaction group and send it to the network.
1361
- * @param params The parameters to control execution with
1362
- * @returns The execution result
1363
- * @example
1364
- * ```typescript
1365
- * const result = await composer.send()
1366
- * ```
1367
- */
1368
- async send(params) {
1369
- const group = (await this.build()).transactions;
1370
- let waitRounds = params?.maxRoundsToWaitForConfirmation;
1371
- const suggestedParams = waitRounds === undefined || params?.coverAppCallInnerTransactionFees ? await this.getSuggestedParams() : undefined;
1372
- if (waitRounds === undefined) {
1373
- const lastRound = group.reduce((max, txn) => (txn.txn.lastValid > max ? txn.txn.lastValid : BigInt(max)), 0n);
1374
- const { firstValid: firstRound } = suggestedParams;
1375
- waitRounds = Number(BigInt(lastRound) - BigInt(firstRound)) + 1;
1376
- }
1377
- try {
1378
- return await sendAtomicTransactionComposer({
1379
- atc: this.atc,
1380
- suppressLog: params?.suppressLog,
1381
- maxRoundsToWaitForConfirmation: waitRounds,
1382
- populateAppCallResources: params?.populateAppCallResources,
1383
- coverAppCallInnerTransactionFees: params?.coverAppCallInnerTransactionFees,
1384
- additionalAtcContext: params?.coverAppCallInnerTransactionFees
1385
- ? {
1386
- maxFees: this.txnMaxFees,
1387
- suggestedParams: suggestedParams,
1388
- }
1389
- : undefined,
1390
- }, this.algod);
1391
- }
1392
- catch (originalError) {
1393
- throw await this.transformError(originalError);
1394
- }
1395
- }
1396
- /**
1397
- * @deprecated Use `send` instead.
1398
- *
1399
- * Compose the atomic transaction group and send it to the network
1400
- *
1401
- * An alias for `composer.send(params)`.
1402
- * @param params The parameters to control execution with
1403
- * @returns The execution result
1404
- */
1405
- async execute(params) {
1406
- return this.send(params);
1407
- }
1408
- async simulate(options) {
1409
- const { skipSignatures = false, ...rawOptions } = options ?? {};
1410
- const atc = skipSignatures ? new AtomicTransactionComposer() : this.atc;
1411
- // Build the transactions
1412
- if (skipSignatures) {
1413
- rawOptions.allowEmptySignatures = true;
1414
- rawOptions.fixSigners = true;
1415
- // Build transactions uses empty signers
1416
- const transactions = await this.buildTransactions();
1417
- for (const txn of transactions.transactions) {
1418
- atc.addTransaction({ txn, signer: TransactionComposer.NULL_SIGNER });
1419
- }
1420
- atc['methodCalls'] = transactions.methodCalls;
1421
- }
1422
- else {
1423
- // Build creates real signatures
1424
- await this.build();
1425
- }
1426
- const { methodResults, simulateResponse } = await atc.simulate(this.algod, new modelsv2.SimulateRequest({
1427
- txnGroups: [],
1428
- ...rawOptions,
1429
- ...(Config.debug
1430
- ? {
1431
- allowEmptySignatures: true,
1432
- fixSigners: true,
1433
- allowMoreLogging: true,
1434
- execTraceConfig: new modelsv2.SimulateTraceConfig({
1435
- enable: true,
1436
- scratchChange: true,
1437
- stackChange: true,
1438
- stateChange: true,
1439
- }),
1440
- }
1441
- : undefined),
1442
- }));
1443
- const failedGroup = simulateResponse?.txnGroups[0];
1444
- if (failedGroup?.failureMessage) {
1445
- const errorMessage = `Transaction failed at transaction(s) ${failedGroup.failedAt?.join(', ') || 'unknown'} in the group. ${failedGroup.failureMessage}`;
1446
- const error = new Error(errorMessage);
1447
- if (Config.debug) {
1448
- await Config.events.emitAsync(EventType.TxnGroupSimulated, { simulateResponse });
1449
- }
1450
- throw await this.transformError(error);
1451
- }
1452
- if (Config.debug && Config.traceAll) {
1453
- await Config.events.emitAsync(EventType.TxnGroupSimulated, { simulateResponse });
1454
- }
1455
- const transactions = atc.buildGroup().map((t) => t.txn);
1456
- const methodCalls = [...atc['methodCalls'].values()];
1457
- return {
1458
- confirmations: simulateResponse.txnGroups[0].txnResults.map((t) => t.txnResult),
1459
- transactions: transactions,
1460
- txIds: transactions.map((t) => t.txID()),
1461
- groupId: Buffer.from(transactions[0].group ?? new Uint8Array()).toString('base64'),
1462
- simulateResponse,
1463
- returns: methodResults.map((r, i) => getABIReturnValue(r, methodCalls[i].returns.type)),
1464
- };
1465
- }
1466
- /**
1467
- * Create an encoded transaction note that follows the ARC-2 spec.
1468
- *
1469
- * https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md
1470
- * @param note The ARC-2 transaction note data
1471
- * @returns The binary encoded transaction note
1472
- */
1473
- static arc2Note(note) {
1474
- const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === 'string' ? note.data : asJson(note.data)}`;
1475
- const encoder = new TextEncoder();
1476
- return encoder.encode(arc2Payload);
1477
- }
1478
- }
1479
- /** Signer used to represent a lack of signer */
1480
- TransactionComposer.NULL_SIGNER = algosdk.makeEmptyTransactionSigner();
27
+ var TransactionComposer = class TransactionComposer {
28
+ /** Signer used to represent a lack of signer */
29
+ static NULL_SIGNER = algosdk.makeEmptyTransactionSigner();
30
+ /** The ATC used to compose the group */
31
+ atc = new algosdk.AtomicTransactionComposer();
32
+ /** Map of transaction index in the atc to a max logical fee.
33
+ * This is set using the value of either maxFee or staticFee.
34
+ */
35
+ txnMaxFees = /* @__PURE__ */ new Map();
36
+ /** Transactions that have not yet been composed */
37
+ txns = [];
38
+ /** The algod client used by the composer. */
39
+ algod;
40
+ /** An async function that will return suggested params for the transaction. */
41
+ getSuggestedParams;
42
+ /** A function that takes in an address and return a signer function for that address. */
43
+ getSigner;
44
+ /** The default transaction validity window */
45
+ defaultValidityWindow = 10n;
46
+ /** Whether the validity window was explicitly set on construction */
47
+ defaultValidityWindowIsExplicit = false;
48
+ appManager;
49
+ errorTransformers;
50
+ async transformError(originalError) {
51
+ if (!(originalError instanceof Error)) return originalError;
52
+ let transformedError = originalError;
53
+ for (const transformer of this.errorTransformers) try {
54
+ transformedError = await transformer(transformedError);
55
+ if (!(transformedError instanceof Error)) return new InvalidErrorTransformerValue(originalError, transformedError);
56
+ } catch (errorFromTransformer) {
57
+ return new ErrorTransformerError(originalError, errorFromTransformer);
58
+ }
59
+ return transformedError;
60
+ }
61
+ /**
62
+ * Create a `TransactionComposer`.
63
+ * @param params The configuration for this composer
64
+ * @returns The `TransactionComposer` instance
65
+ */
66
+ constructor(params) {
67
+ this.algod = params.algod;
68
+ const defaultGetSuggestedParams = () => params.algod.getTransactionParams().do();
69
+ this.getSuggestedParams = params.getSuggestedParams ?? defaultGetSuggestedParams;
70
+ this.getSigner = params.getSigner;
71
+ this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
72
+ this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== void 0;
73
+ this.appManager = params.appManager ?? new AppManager(params.algod);
74
+ this.errorTransformers = params.errorTransformers ?? [];
75
+ }
76
+ /**
77
+ * Register a function that will be used to transform an error caught when simulating or executing
78
+ *
79
+ * @returns The composer so you can chain method calls
80
+ */
81
+ registerErrorTransformer(transformer) {
82
+ this.errorTransformers.push(transformer);
83
+ return this;
84
+ }
85
+ /**
86
+ * Add a pre-built transaction to the transaction group.
87
+ * @param transaction The pre-built transaction
88
+ * @param signer Optional signer override for the transaction
89
+ * @returns The composer so you can chain method calls
90
+ * @example
91
+ * ```typescript
92
+ * composer.addTransaction(txn)
93
+ * ```
94
+ */
95
+ addTransaction(transaction, signer) {
96
+ this.txns.push({
97
+ txn: transaction,
98
+ signer: signer ?? this.getSigner(transaction.sender),
99
+ type: "txnWithSigner"
100
+ });
101
+ return this;
102
+ }
103
+ /**
104
+ * Add a payment transaction to the transaction group.
105
+ * @param params The payment transaction parameters
106
+ * @returns The composer so you can chain method calls
107
+ * @example Basic example
108
+ * ```typescript
109
+ * composer.addPayment({
110
+ * sender: 'SENDERADDRESS',
111
+ * receiver: 'RECEIVERADDRESS',
112
+ * amount: (4).algo(),
113
+ * })
114
+ * ```
115
+ * @example Advanced example
116
+ * ```typescript
117
+ * composer.addPayment({
118
+ * amount: (4).algo(),
119
+ * receiver: 'RECEIVERADDRESS',
120
+ * sender: 'SENDERADDRESS',
121
+ * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS',
122
+ * lease: 'lease',
123
+ * note: 'note',
124
+ * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
125
+ * rekeyTo: 'REKEYTOADDRESS',
126
+ * // You wouldn't normally set this field
127
+ * firstValidRound: 1000n,
128
+ * validityWindow: 10,
129
+ * extraFee: (1000).microAlgo(),
130
+ * staticFee: (1000).microAlgo(),
131
+ * // Max fee doesn't make sense with extraFee AND staticFee
132
+ * // already specified, but here for completeness
133
+ * maxFee: (3000).microAlgo(),
134
+ * })
135
+ */
136
+ addPayment(params) {
137
+ this.txns.push({
138
+ ...params,
139
+ type: "pay"
140
+ });
141
+ return this;
142
+ }
143
+ /**
144
+ * Add an asset create transaction to the transaction group.
145
+ * @param params The asset create transaction parameters
146
+ * @returns The composer so you can chain method calls
147
+ * @example Basic example
148
+ * ```typescript
149
+ * composer.addAssetCreate({ sender: "CREATORADDRESS", total: 100n})
150
+ * ```
151
+ * @example Advanced example
152
+ * ```typescript
153
+ * composer.addAssetCreate({
154
+ * sender: 'CREATORADDRESS',
155
+ * total: 100n,
156
+ * decimals: 2,
157
+ * assetName: 'asset',
158
+ * unitName: 'unit',
159
+ * url: 'url',
160
+ * metadataHash: 'metadataHash',
161
+ * defaultFrozen: false,
162
+ * manager: 'MANAGERADDRESS',
163
+ * reserve: 'RESERVEADDRESS',
164
+ * freeze: 'FREEZEADDRESS',
165
+ * clawback: 'CLAWBACKADDRESS',
166
+ * lease: 'lease',
167
+ * note: 'note',
168
+ * // You wouldn't normally set this field
169
+ * firstValidRound: 1000n,
170
+ * validityWindow: 10,
171
+ * extraFee: (1000).microAlgo(),
172
+ * staticFee: (1000).microAlgo(),
173
+ * // Max fee doesn't make sense with extraFee AND staticFee
174
+ * // already specified, but here for completeness
175
+ * maxFee: (3000).microAlgo(),
176
+ * })
177
+ */
178
+ addAssetCreate(params) {
179
+ this.txns.push({
180
+ ...params,
181
+ type: "assetCreate"
182
+ });
183
+ return this;
184
+ }
185
+ /**
186
+ * Add an asset config transaction to the transaction group.
187
+ * @param params The asset config transaction parameters
188
+ * @returns The composer so you can chain method calls
189
+ * @example Basic example
190
+ * ```typescript
191
+ * composer.addAssetConfig({ sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" })
192
+ * ```
193
+ * @example Advanced example
194
+ * ```typescript
195
+ * composer.addAssetConfig({
196
+ * sender: 'MANAGERADDRESS',
197
+ * assetId: 123456n,
198
+ * manager: 'MANAGERADDRESS',
199
+ * reserve: 'RESERVEADDRESS',
200
+ * freeze: 'FREEZEADDRESS',
201
+ * clawback: 'CLAWBACKADDRESS',
202
+ * lease: 'lease',
203
+ * note: 'note',
204
+ * // You wouldn't normally set this field
205
+ * firstValidRound: 1000n,
206
+ * validityWindow: 10,
207
+ * extraFee: (1000).microAlgo(),
208
+ * staticFee: (1000).microAlgo(),
209
+ * // Max fee doesn't make sense with extraFee AND staticFee
210
+ * // already specified, but here for completeness
211
+ * maxFee: (3000).microAlgo(),
212
+ * })
213
+ */
214
+ addAssetConfig(params) {
215
+ this.txns.push({
216
+ ...params,
217
+ type: "assetConfig"
218
+ });
219
+ return this;
220
+ }
221
+ /**
222
+ * Add an asset freeze transaction to the transaction group.
223
+ * @param params The asset freeze transaction parameters
224
+ * @returns The composer so you can chain method calls
225
+ * @example Basic example
226
+ * ```typescript
227
+ * composer.addAssetFreeze({ sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true })
228
+ * ```
229
+ * @example Advanced example
230
+ * ```typescript
231
+ * composer.addAssetFreeze({
232
+ * sender: 'MANAGERADDRESS',
233
+ * assetId: 123456n,
234
+ * account: 'ACCOUNTADDRESS',
235
+ * frozen: true,
236
+ * lease: 'lease',
237
+ * note: 'note',
238
+ * // You wouldn't normally set this field
239
+ * firstValidRound: 1000n,
240
+ * validityWindow: 10,
241
+ * extraFee: (1000).microAlgo(),
242
+ * staticFee: (1000).microAlgo(),
243
+ * // Max fee doesn't make sense with extraFee AND staticFee
244
+ * // already specified, but here for completeness
245
+ * maxFee: (3000).microAlgo(),
246
+ * })
247
+ * ```
248
+ */
249
+ addAssetFreeze(params) {
250
+ this.txns.push({
251
+ ...params,
252
+ type: "assetFreeze"
253
+ });
254
+ return this;
255
+ }
256
+ /**
257
+ * Add an asset destroy transaction to the transaction group.
258
+ * @param params The asset destroy transaction parameters
259
+ * @returns The composer so you can chain method calls
260
+ * @example Basic example
261
+ * ```typescript
262
+ * composer.addAssetDestroy({ sender: "MANAGERADDRESS", assetId: 123456n })
263
+ * ```
264
+ * @example Advanced example
265
+ * ```typescript
266
+ * composer.addAssetDestroy({
267
+ * sender: 'MANAGERADDRESS',
268
+ * assetId: 123456n,
269
+ * lease: 'lease',
270
+ * note: 'note',
271
+ * // You wouldn't normally set this field
272
+ * firstValidRound: 1000n,
273
+ * validityWindow: 10,
274
+ * extraFee: (1000).microAlgo(),
275
+ * staticFee: (1000).microAlgo(),
276
+ * // Max fee doesn't make sense with extraFee AND staticFee
277
+ * // already specified, but here for completeness
278
+ * maxFee: (3000).microAlgo(),
279
+ * })
280
+ * ```
281
+ */
282
+ addAssetDestroy(params) {
283
+ this.txns.push({
284
+ ...params,
285
+ type: "assetDestroy"
286
+ });
287
+ return this;
288
+ }
289
+ /**
290
+ * Add an asset transfer transaction to the transaction group.
291
+ * @param params The asset transfer transaction parameters
292
+ * @returns The composer so you can chain method calls
293
+ * @example Basic example
294
+ * ```typescript
295
+ * composer.addAssetTransfer({ sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" })
296
+ * ```
297
+ * @example Advanced example (with clawback)
298
+ * ```typescript
299
+ * composer.addAssetTransfer({
300
+ * sender: 'CLAWBACKADDRESS',
301
+ * assetId: 123456n,
302
+ * amount: 1n,
303
+ * receiver: 'RECEIVERADDRESS',
304
+ * clawbackTarget: 'HOLDERADDRESS',
305
+ * // This field needs to be used with caution
306
+ * closeAssetTo: 'ADDRESSTOCLOSETO'
307
+ * lease: 'lease',
308
+ * note: 'note',
309
+ * // You wouldn't normally set this field
310
+ * firstValidRound: 1000n,
311
+ * validityWindow: 10,
312
+ * extraFee: (1000).microAlgo(),
313
+ * staticFee: (1000).microAlgo(),
314
+ * // Max fee doesn't make sense with extraFee AND staticFee
315
+ * // already specified, but here for completeness
316
+ * maxFee: (3000).microAlgo(),
317
+ * })
318
+ * ```
319
+ */
320
+ addAssetTransfer(params) {
321
+ this.txns.push({
322
+ ...params,
323
+ type: "assetTransfer"
324
+ });
325
+ return this;
326
+ }
327
+ /**
328
+ * Add an asset opt-in transaction to the transaction group.
329
+ * @param params The asset opt-in transaction parameters
330
+ * @returns The composer so you can chain method calls
331
+ * @example Basic example
332
+ * ```typescript
333
+ * composer.addAssetOptIn({ sender: "SENDERADDRESS", assetId: 123456n })
334
+ * ```
335
+ * @example Advanced example
336
+ * ```typescript
337
+ * composer.addAssetOptIn({
338
+ * sender: 'SENDERADDRESS',
339
+ * assetId: 123456n,
340
+ * lease: 'lease',
341
+ * note: 'note',
342
+ * // You wouldn't normally set this field
343
+ * firstValidRound: 1000n,
344
+ * validityWindow: 10,
345
+ * extraFee: (1000).microAlgo(),
346
+ * staticFee: (1000).microAlgo(),
347
+ * // Max fee doesn't make sense with extraFee AND staticFee
348
+ * // already specified, but here for completeness
349
+ * maxFee: (3000).microAlgo(),
350
+ * })
351
+ * ```
352
+ */
353
+ addAssetOptIn(params) {
354
+ this.txns.push({
355
+ ...params,
356
+ type: "assetOptIn"
357
+ });
358
+ return this;
359
+ }
360
+ /**
361
+ * Add an asset opt-out transaction to the transaction group.
362
+ * @param params The asset opt-out transaction parameters
363
+ * @returns The composer so you can chain method calls
364
+ * @example Basic example (without creator, will be retrieved from algod)
365
+ * ```typescript
366
+ * composer.addAssetOptOut({ sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true })
367
+ * ```
368
+ * @example Basic example (with creator)
369
+ * ```typescript
370
+ * composer.addAssetOptOut({ sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true })
371
+ * ```
372
+ * @example Advanced example
373
+ * ```typescript
374
+ * composer.addAssetOptOut({
375
+ * sender: 'SENDERADDRESS',
376
+ * assetId: 123456n,
377
+ * creator: 'CREATORADDRESS',
378
+ * ensureZeroBalance: true,
379
+ * lease: 'lease',
380
+ * note: 'note',
381
+ * // You wouldn't normally set this field
382
+ * firstValidRound: 1000n,
383
+ * validityWindow: 10,
384
+ * extraFee: (1000).microAlgo(),
385
+ * staticFee: (1000).microAlgo(),
386
+ * // Max fee doesn't make sense with extraFee AND staticFee
387
+ * // already specified, but here for completeness
388
+ * maxFee: (3000).microAlgo(),
389
+ * })
390
+ * ```
391
+ */
392
+ addAssetOptOut(params) {
393
+ this.txns.push({
394
+ ...params,
395
+ type: "assetOptOut"
396
+ });
397
+ return this;
398
+ }
399
+ /**
400
+ * Add an application create transaction to the transaction group.
401
+ *
402
+ * Note: we recommend using app clients to make it easier to make app calls.
403
+ * @param params The application create transaction parameters
404
+ * @returns The composer so you can chain method calls
405
+ * @example Basic example
406
+ * ```typescript
407
+ * composer.addAppCreate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
408
+ * ```
409
+ * @example Advanced example
410
+ * ```typescript
411
+ * composer.addAppCreate({
412
+ * sender: 'CREATORADDRESS',
413
+ * approvalProgram: "TEALCODE",
414
+ * clearStateProgram: "TEALCODE",
415
+ * schema: {
416
+ * globalInts: 1,
417
+ * globalByteSlices: 2,
418
+ * localInts: 3,
419
+ * localByteSlices: 4
420
+ * },
421
+ * extraProgramPages: 1,
422
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
423
+ * args: [new Uint8Array(1, 2, 3, 4)]
424
+ * accountReferences: ["ACCOUNT_1"]
425
+ * appReferences: [123n, 1234n]
426
+ * assetReferences: [12345n]
427
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
428
+ * accessReferences: [{ appId: 1234n }]
429
+ * lease: 'lease',
430
+ * note: 'note',
431
+ * // You wouldn't normally set this field
432
+ * firstValidRound: 1000n,
433
+ * validityWindow: 10,
434
+ * extraFee: (1000).microAlgo(),
435
+ * staticFee: (1000).microAlgo(),
436
+ * // Max fee doesn't make sense with extraFee AND staticFee
437
+ * // already specified, but here for completeness
438
+ * maxFee: (3000).microAlgo(),
439
+ * rejectVersion: 1,
440
+ * // Signer only needed if you want to provide one,
441
+ * // generally you'd register it with AlgorandClient
442
+ * // against the sender and not need to pass it in
443
+ * signer: transactionSigner,
444
+ * maxRoundsToWaitForConfirmation: 5,
445
+ * suppressLog: true,
446
+ *})
447
+ * ```
448
+ */
449
+ addAppCreate(params) {
450
+ this.txns.push({
451
+ ...params,
452
+ type: "appCall"
453
+ });
454
+ return this;
455
+ }
456
+ /**
457
+ * Add an application update transaction to the transaction group.
458
+ *
459
+ * Note: we recommend using app clients to make it easier to make app calls.
460
+ * @param params The application update transaction parameters
461
+ * @returns The composer so you can chain method calls
462
+ * @example Basic example
463
+ * ```typescript
464
+ * composer.addAppUpdate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
465
+ * ```
466
+ * @example Advanced example
467
+ * ```typescript
468
+ * composer.addAppUpdate({
469
+ * sender: 'CREATORADDRESS',
470
+ * approvalProgram: "TEALCODE",
471
+ * clearStateProgram: "TEALCODE",
472
+ * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
473
+ * args: [new Uint8Array(1, 2, 3, 4)]
474
+ * accountReferences: ["ACCOUNT_1"]
475
+ * appReferences: [123n, 1234n]
476
+ * assetReferences: [12345n]
477
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
478
+ * accessReferences: [{ appId: 1234n }]
479
+ * lease: 'lease',
480
+ * note: 'note',
481
+ * // You wouldn't normally set this field
482
+ * firstValidRound: 1000n,
483
+ * validityWindow: 10,
484
+ * extraFee: (1000).microAlgo(),
485
+ * staticFee: (1000).microAlgo(),
486
+ * // Max fee doesn't make sense with extraFee AND staticFee
487
+ * // already specified, but here for completeness
488
+ * maxFee: (3000).microAlgo(),
489
+ * rejectVersion: 1,
490
+ *})
491
+ * ```
492
+ */
493
+ addAppUpdate(params) {
494
+ this.txns.push({
495
+ ...params,
496
+ type: "appCall",
497
+ onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC
498
+ });
499
+ return this;
500
+ }
501
+ /**
502
+ * Add an application delete transaction to the transaction group.
503
+ *
504
+ * Note: we recommend using app clients to make it easier to make app calls.
505
+ * @param params The application delete transaction parameters
506
+ * @returns The composer so you can chain method calls
507
+ * @example Basic example
508
+ * ```typescript
509
+ * composer.addAppDelete({ sender: 'CREATORADDRESS' })
510
+ * ```
511
+ * @example Advanced example
512
+ * ```typescript
513
+ * composer.addAppDelete({
514
+ * sender: 'CREATORADDRESS',
515
+ * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
516
+ * args: [new Uint8Array(1, 2, 3, 4)]
517
+ * accountReferences: ["ACCOUNT_1"]
518
+ * appReferences: [123n, 1234n]
519
+ * assetReferences: [12345n]
520
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
521
+ * accessReferences: [{ appId: 1234n }]
522
+ * lease: 'lease',
523
+ * note: 'note',
524
+ * // You wouldn't normally set this field
525
+ * firstValidRound: 1000n,
526
+ * validityWindow: 10,
527
+ * extraFee: (1000).microAlgo(),
528
+ * staticFee: (1000).microAlgo(),
529
+ * // Max fee doesn't make sense with extraFee AND staticFee
530
+ * // already specified, but here for completeness
531
+ * maxFee: (3000).microAlgo(),
532
+ * rejectVersion: 1,
533
+ *})
534
+ * ```
535
+ */
536
+ addAppDelete(params) {
537
+ this.txns.push({
538
+ ...params,
539
+ type: "appCall",
540
+ onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC
541
+ });
542
+ return this;
543
+ }
544
+ /**
545
+ * Add an application call transaction to the transaction group.
546
+ *
547
+ * If you want to create or update an app use `addAppCreate` or `addAppUpdate`.
548
+ *
549
+ * Note: we recommend using app clients to make it easier to make app calls.
550
+ * @param params The application call transaction parameters
551
+ * @returns The composer so you can chain method calls
552
+ * @example Basic example
553
+ * ```typescript
554
+ * composer.addAppCall({ sender: 'CREATORADDRESS' })
555
+ * ```
556
+ * @example Advanced example
557
+ * ```typescript
558
+ * composer.addAppCall({
559
+ * sender: 'CREATORADDRESS',
560
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
561
+ * args: [new Uint8Array(1, 2, 3, 4)]
562
+ * accountReferences: ["ACCOUNT_1"]
563
+ * appReferences: [123n, 1234n]
564
+ * assetReferences: [12345n]
565
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
566
+ * accessReferences: [{ appId: 1234n }]
567
+ * lease: 'lease',
568
+ * note: 'note',
569
+ * // You wouldn't normally set this field
570
+ * firstValidRound: 1000n,
571
+ * validityWindow: 10,
572
+ * extraFee: (1000).microAlgo(),
573
+ * staticFee: (1000).microAlgo(),
574
+ * // Max fee doesn't make sense with extraFee AND staticFee
575
+ * // already specified, but here for completeness
576
+ * maxFee: (3000).microAlgo(),
577
+ * rejectVersion: 1,
578
+ *})
579
+ * ```
580
+ */
581
+ addAppCall(params) {
582
+ this.txns.push({
583
+ ...params,
584
+ type: "appCall"
585
+ });
586
+ return this;
587
+ }
588
+ /**
589
+ * Add an ABI method create application call transaction to the transaction group.
590
+ *
591
+ * Note: we recommend using app clients to make it easier to make app calls.
592
+ * @param params The ABI create method application call transaction parameters
593
+ * @returns The composer so you can chain method calls
594
+ * @example Basic example
595
+ * ```typescript
596
+ * const method = new ABIMethod({
597
+ * name: 'method',
598
+ * args: [{ name: 'arg1', type: 'string' }],
599
+ * returns: { type: 'string' },
600
+ * })
601
+ * composer.addAppCreateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
602
+ * ```
603
+ * @example Advanced example
604
+ * ```typescript
605
+ * const method = new ABIMethod({
606
+ * name: 'method',
607
+ * args: [{ name: 'arg1', type: 'string' }],
608
+ * returns: { type: 'string' },
609
+ * })
610
+ * composer.addAppCreateMethodCall({
611
+ * sender: 'CREATORADDRESS',
612
+ * method: method,
613
+ * args: ["arg1_value"],
614
+ * approvalProgram: "TEALCODE",
615
+ * clearStateProgram: "TEALCODE",
616
+ * schema: {
617
+ * globalInts: 1,
618
+ * globalByteSlices: 2,
619
+ * localInts: 3,
620
+ * localByteSlices: 4
621
+ * },
622
+ * extraProgramPages: 1,
623
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
624
+ * args: [new Uint8Array(1, 2, 3, 4)]
625
+ * accountReferences: ["ACCOUNT_1"]
626
+ * appReferences: [123n, 1234n]
627
+ * assetReferences: [12345n]
628
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
629
+ * accessReferences: [{ appId: 1234n }]
630
+ * lease: 'lease',
631
+ * note: 'note',
632
+ * // You wouldn't normally set this field
633
+ * firstValidRound: 1000n,
634
+ * validityWindow: 10,
635
+ * extraFee: (1000).microAlgo(),
636
+ * staticFee: (1000).microAlgo(),
637
+ * // Max fee doesn't make sense with extraFee AND staticFee
638
+ * // already specified, but here for completeness
639
+ * maxFee: (3000).microAlgo(),
640
+ * rejectVersion: 1,
641
+ *})
642
+ * ```
643
+ */
644
+ addAppCreateMethodCall(params) {
645
+ this.txns.push({
646
+ ...params,
647
+ type: "methodCall"
648
+ });
649
+ return this;
650
+ }
651
+ /**
652
+ * Add an ABI method update application call transaction to the transaction group.
653
+ *
654
+ * Note: we recommend using app clients to make it easier to make app calls.
655
+ * @param params The ABI update method application call transaction parameters
656
+ * @returns The composer so you can chain method calls
657
+ * @example Basic example
658
+ * ```typescript
659
+ * const method = new ABIMethod({
660
+ * name: 'method',
661
+ * args: [{ name: 'arg1', type: 'string' }],
662
+ * returns: { type: 'string' },
663
+ * })
664
+ * composer.addAppUpdateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
665
+ * ```
666
+ * @example Advanced example
667
+ * ```typescript
668
+ * const method = new ABIMethod({
669
+ * name: 'method',
670
+ * args: [{ name: 'arg1', type: 'string' }],
671
+ * returns: { type: 'string' },
672
+ * })
673
+ * composer.addAppUpdateMethodCall({
674
+ * sender: 'CREATORADDRESS',
675
+ * method: method,
676
+ * args: ["arg1_value"],
677
+ * approvalProgram: "TEALCODE",
678
+ * clearStateProgram: "TEALCODE",
679
+ * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
680
+ * args: [new Uint8Array(1, 2, 3, 4)]
681
+ * accountReferences: ["ACCOUNT_1"]
682
+ * appReferences: [123n, 1234n]
683
+ * assetReferences: [12345n]
684
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
685
+ * accessReferences: [{ appId: 1234n }]
686
+ * lease: 'lease',
687
+ * note: 'note',
688
+ * // You wouldn't normally set this field
689
+ * firstValidRound: 1000n,
690
+ * validityWindow: 10,
691
+ * extraFee: (1000).microAlgo(),
692
+ * staticFee: (1000).microAlgo(),
693
+ * // Max fee doesn't make sense with extraFee AND staticFee
694
+ * // already specified, but here for completeness
695
+ * maxFee: (3000).microAlgo(),
696
+ * rejectVersion: 1,
697
+ *})
698
+ * ```
699
+ */
700
+ addAppUpdateMethodCall(params) {
701
+ this.txns.push({
702
+ ...params,
703
+ type: "methodCall",
704
+ onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC
705
+ });
706
+ return this;
707
+ }
708
+ /**
709
+ * Add an ABI method delete application call transaction to the transaction group.
710
+ *
711
+ * Note: we recommend using app clients to make it easier to make app calls.
712
+ * @param params The ABI delete method application call transaction parameters
713
+ * @returns The composer so you can chain method calls
714
+ * @example Basic example
715
+ * ```typescript
716
+ * const method = new ABIMethod({
717
+ * name: 'method',
718
+ * args: [{ name: 'arg1', type: 'string' }],
719
+ * returns: { type: 'string' },
720
+ * })
721
+ * composer.addAppDeleteMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
722
+ * ```
723
+ * @example Advanced example
724
+ * ```typescript
725
+ * const method = new ABIMethod({
726
+ * name: 'method',
727
+ * args: [{ name: 'arg1', type: 'string' }],
728
+ * returns: { type: 'string' },
729
+ * })
730
+ * composer.addAppDeleteMethodCall({
731
+ * sender: 'CREATORADDRESS',
732
+ * method: method,
733
+ * args: ["arg1_value"],
734
+ * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
735
+ * args: [new Uint8Array(1, 2, 3, 4)]
736
+ * accountReferences: ["ACCOUNT_1"]
737
+ * appReferences: [123n, 1234n]
738
+ * assetReferences: [12345n]
739
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
740
+ * accessReferences: [{ appId: 1234n }]
741
+ * lease: 'lease',
742
+ * note: 'note',
743
+ * // You wouldn't normally set this field
744
+ * firstValidRound: 1000n,
745
+ * validityWindow: 10,
746
+ * extraFee: (1000).microAlgo(),
747
+ * staticFee: (1000).microAlgo(),
748
+ * // Max fee doesn't make sense with extraFee AND staticFee
749
+ * // already specified, but here for completeness
750
+ * maxFee: (3000).microAlgo(),
751
+ * rejectVersion: 1,
752
+ *})
753
+ * ```
754
+ */
755
+ addAppDeleteMethodCall(params) {
756
+ this.txns.push({
757
+ ...params,
758
+ type: "methodCall",
759
+ onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC
760
+ });
761
+ return this;
762
+ }
763
+ /**
764
+ * Add a non-create/non-update ABI method application call transaction to the transaction group.
765
+ *
766
+ * Note: we recommend using app clients to make it easier to make app calls.
767
+ * @param params The ABI method application call transaction parameters
768
+ * @returns The composer so you can chain method calls
769
+ * @example Basic example
770
+ * ```typescript
771
+ * const method = new ABIMethod({
772
+ * name: 'method',
773
+ * args: [{ name: 'arg1', type: 'string' }],
774
+ * returns: { type: 'string' },
775
+ * })
776
+ * composer.addAppCallMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
777
+ * ```
778
+ * @example Advanced example
779
+ * ```typescript
780
+ * const method = new ABIMethod({
781
+ * name: 'method',
782
+ * args: [{ name: 'arg1', type: 'string' }],
783
+ * returns: { type: 'string' },
784
+ * })
785
+ * composer.addAppCallMethodCall({
786
+ * sender: 'CREATORADDRESS',
787
+ * method: method,
788
+ * args: ["arg1_value"],
789
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
790
+ * args: [new Uint8Array(1, 2, 3, 4)]
791
+ * accountReferences: ["ACCOUNT_1"]
792
+ * appReferences: [123n, 1234n]
793
+ * assetReferences: [12345n]
794
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
795
+ * accessReferences: [{ appId: 1234n }]
796
+ * lease: 'lease',
797
+ * note: 'note',
798
+ * // You wouldn't normally set this field
799
+ * firstValidRound: 1000n,
800
+ * validityWindow: 10,
801
+ * extraFee: (1000).microAlgo(),
802
+ * staticFee: (1000).microAlgo(),
803
+ * // Max fee doesn't make sense with extraFee AND staticFee
804
+ * // already specified, but here for completeness
805
+ * maxFee: (3000).microAlgo(),
806
+ * rejectVersion: 1,
807
+ *})
808
+ * ```
809
+ */
810
+ addAppCallMethodCall(params) {
811
+ this.txns.push({
812
+ ...params,
813
+ type: "methodCall"
814
+ });
815
+ return this;
816
+ }
817
+ /**
818
+ * Add an online key registration transaction to the transaction group.
819
+ * @param params The online key registration transaction parameters
820
+ * @returns The composer so you can chain method calls
821
+ * @example Basic example
822
+ * ```typescript
823
+ * composer.addOnlineKeyRegistration({
824
+ * sender: 'SENDERADDRESS',
825
+ * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
826
+ * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
827
+ * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
828
+ * voteFirst: 1n,
829
+ * voteLast: 1000n,
830
+ * voteKeyDilution: 1n,
831
+ * })
832
+ * ```
833
+ * @example Advanced example
834
+ * ```typescript
835
+ * composer.addOnlineKeyRegistration({
836
+ * sender: 'SENDERADDRESS',
837
+ * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
838
+ * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
839
+ * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
840
+ * voteFirst: 1n,
841
+ * voteLast: 1000n,
842
+ * voteKeyDilution: 1n,
843
+ * lease: 'lease',
844
+ * note: 'note',
845
+ * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
846
+ * rekeyTo: 'REKEYTOADDRESS',
847
+ * // You wouldn't normally set this field
848
+ * firstValidRound: 1000n,
849
+ * validityWindow: 10,
850
+ * extraFee: (1000).microAlgo(),
851
+ * staticFee: (1000).microAlgo(),
852
+ * // Max fee doesn't make sense with extraFee AND staticFee
853
+ * // already specified, but here for completeness
854
+ * maxFee: (3000).microAlgo(),
855
+ * })
856
+ * ```
857
+ */
858
+ addOnlineKeyRegistration(params) {
859
+ this.txns.push({
860
+ ...params,
861
+ type: "keyReg"
862
+ });
863
+ return this;
864
+ }
865
+ /**
866
+ * Add an offline key registration transaction to the transaction group.
867
+ * @param params The offline key registration transaction parameters
868
+ * @returns The composer so you can chain method calls
869
+ * @example Basic example
870
+ * ```typescript
871
+ * composer.addOfflineKeyRegistration({
872
+ * sender: 'SENDERADDRESS',
873
+ * })
874
+ * ```
875
+ * @example Advanced example
876
+ * ```typescript
877
+ * composer.addOfflineKeyRegistration({
878
+ * sender: 'SENDERADDRESS',
879
+ * lease: 'lease',
880
+ * note: 'note',
881
+ * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
882
+ * rekeyTo: 'REKEYTOADDRESS',
883
+ * // You wouldn't normally set this field
884
+ * firstValidRound: 1000n,
885
+ * validityWindow: 10,
886
+ * extraFee: (1000).microAlgo(),
887
+ * staticFee: (1000).microAlgo(),
888
+ * // Max fee doesn't make sense with extraFee AND staticFee
889
+ * // already specified, but here for completeness
890
+ * maxFee: (3000).microAlgo(),
891
+ * })
892
+ * ```
893
+ */
894
+ addOfflineKeyRegistration(params) {
895
+ this.txns.push({
896
+ ...params,
897
+ type: "keyReg"
898
+ });
899
+ return this;
900
+ }
901
+ /**
902
+ * Add the transactions within an `AtomicTransactionComposer` to the transaction group.
903
+ * @param atc The `AtomicTransactionComposer` to build transactions from and add to the group
904
+ * @returns The composer so you can chain method calls
905
+ * @example
906
+ * ```typescript
907
+ * const atc = new AtomicTransactionComposer()
908
+ * .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: 1000n })
909
+ * composer.addAtc(atc)
910
+ * ```
911
+ */
912
+ addAtc(atc) {
913
+ this.txns.push({
914
+ atc,
915
+ type: "atc"
916
+ });
917
+ return this;
918
+ }
919
+ /** Build an ATC and return transactions ready to be incorporated into a broader set of transactions this composer is composing */
920
+ buildAtc(atc) {
921
+ return atc.buildGroup().map((ts, idx) => {
922
+ ts.txn.group = void 0;
923
+ if (atc["methodCalls"].get(idx)) return {
924
+ ...ts,
925
+ context: { abiMethod: atc["methodCalls"].get(idx) }
926
+ };
927
+ return {
928
+ ...ts,
929
+ context: {}
930
+ };
931
+ });
932
+ }
933
+ commonTxnBuildStep(buildTxn, params, txnParams) {
934
+ txnParams.suggestedParams = { ...txnParams.suggestedParams };
935
+ if (params.lease) txnParams.lease = encodeLease(params.lease);
936
+ if (params.rekeyTo) txnParams.rekeyTo = address(params.rekeyTo);
937
+ const encoder = new TextEncoder();
938
+ if (params.note) txnParams.note = typeof params.note === "string" ? encoder.encode(params.note) : params.note;
939
+ if (params.firstValidRound) txnParams.suggestedParams.firstValid = params.firstValidRound;
940
+ if (params.lastValidRound) txnParams.suggestedParams.lastValid = params.lastValidRound;
941
+ else {
942
+ const window = params.validityWindow ? BigInt(params.validityWindow) : !this.defaultValidityWindowIsExplicit && genesisIdIsLocalNet(txnParams.suggestedParams.genesisID ?? "unknown") ? 1000n : this.defaultValidityWindow;
943
+ txnParams.suggestedParams.lastValid = BigInt(txnParams.suggestedParams.firstValid) + window;
944
+ }
945
+ if (params.staticFee !== void 0 && params.extraFee !== void 0) throw Error("Cannot set both staticFee and extraFee");
946
+ if (params.staticFee !== void 0) {
947
+ txnParams.suggestedParams.fee = params.staticFee.microAlgo;
948
+ txnParams.suggestedParams.flatFee = true;
949
+ }
950
+ const txn = buildTxn(txnParams);
951
+ if (params.extraFee) txn.fee += params.extraFee.microAlgo;
952
+ if (params.maxFee !== void 0 && txn.fee > params.maxFee.microAlgo) throw Error(`Transaction fee ${txn.fee} µALGO is greater than maxFee ${params.maxFee}`);
953
+ return {
954
+ txn,
955
+ context: { maxFee: params.maxFee !== void 0 && params.maxFee.microAlgo > (params.staticFee?.microAlgo ?? 0n) ? params.maxFee : params.staticFee }
956
+ };
957
+ }
958
+ /**
959
+ * Builds an ABI method call transaction and any other associated transactions represented in the ABI args.
960
+ * @param includeSigner Whether to include the actual signer for the transactions.
961
+ * If you are just building transactions without signers yet then set this to `false`.
962
+ */
963
+ async buildMethodCall(params, suggestedParams, includeSigner) {
964
+ const methodArgs = [];
965
+ const transactionsForGroup = [];
966
+ const isAbiValue = (x) => {
967
+ if (Array.isArray(x)) return x.length == 0 || x.every(isAbiValue);
968
+ return typeof x === "bigint" || typeof x === "boolean" || typeof x === "number" || typeof x === "string" || x instanceof Uint8Array || x instanceof algosdk.Address;
969
+ };
970
+ for (let i = (params.args ?? []).length - 1; i >= 0; i--) {
971
+ const arg = params.args[i];
972
+ if (arg === void 0) {
973
+ if (algosdk.abiTypeIsTransaction(params.method.args[i].type) && transactionsForGroup.length > 0) {
974
+ const placeholderTransaction = transactionsForGroup.splice(-1, 1)[0];
975
+ methodArgs.push(placeholderTransaction);
976
+ continue;
977
+ }
978
+ throw Error(`No value provided for argument ${i + 1} within call to ${params.method.name}`);
979
+ }
980
+ if (isAbiValue(arg)) {
981
+ methodArgs.push(arg);
982
+ continue;
983
+ }
984
+ if (isTransactionWithSigner(arg)) {
985
+ methodArgs.push(arg);
986
+ continue;
987
+ }
988
+ if ("method" in arg) {
989
+ const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams, includeSigner);
990
+ methodArgs.push(...tempTxnWithSigners.slice(-1));
991
+ transactionsForGroup.push(...tempTxnWithSigners.slice(0, -1).reverse());
992
+ continue;
993
+ }
994
+ const txn = await arg;
995
+ methodArgs.push({
996
+ txn,
997
+ signer: includeSigner ? params.signer ? "signer" in params.signer ? params.signer.signer : params.signer : this.getSigner(txn.sender) : TransactionComposer.NULL_SIGNER
998
+ });
999
+ }
1000
+ const methodAtc = new algosdk.AtomicTransactionComposer();
1001
+ const maxFees = /* @__PURE__ */ new Map();
1002
+ transactionsForGroup.reverse().forEach(({ context, ...txnWithSigner }) => {
1003
+ methodAtc.addTransaction(txnWithSigner);
1004
+ const atcIndex = methodAtc.count() - 1;
1005
+ if (context.abiMethod) methodAtc["methodCalls"].set(atcIndex, context.abiMethod);
1006
+ if (context.maxFee !== void 0) maxFees.set(atcIndex, context.maxFee);
1007
+ });
1008
+ methodArgs.filter((arg) => {
1009
+ if (typeof arg === "object" && "context" in arg) {
1010
+ const { context, ...txnWithSigner } = arg;
1011
+ return isTransactionWithSigner(txnWithSigner);
1012
+ }
1013
+ return isTransactionWithSigner(arg);
1014
+ }).reverse().forEach((arg, idx) => {
1015
+ if (typeof arg === "object" && "context" in arg && arg.context) {
1016
+ const atcIndex = methodAtc.count() + idx;
1017
+ if (arg.context.abiMethod) methodAtc["methodCalls"].set(atcIndex, arg.context.abiMethod);
1018
+ if (arg.context.maxFee !== void 0) maxFees.set(atcIndex, arg.context.maxFee);
1019
+ }
1020
+ });
1021
+ const appId = Number("appId" in params ? params.appId : 0n);
1022
+ const approvalProgram = "approvalProgram" in params ? typeof params.approvalProgram === "string" ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes : params.approvalProgram : void 0;
1023
+ const clearStateProgram = "clearStateProgram" in params ? typeof params.clearStateProgram === "string" ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes : params.clearStateProgram : void 0;
1024
+ const txnParams = {
1025
+ appID: appId,
1026
+ sender: params.sender,
1027
+ suggestedParams,
1028
+ onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
1029
+ appAccounts: params.accountReferences,
1030
+ appForeignApps: params.appReferences?.map((x) => Number(x)),
1031
+ appForeignAssets: params.assetReferences?.map((x) => Number(x)),
1032
+ boxes: params.boxReferences?.map(AppManager.getBoxReference),
1033
+ access: params.accessReferences?.map(getResourceReference),
1034
+ approvalProgram,
1035
+ clearProgram: clearStateProgram,
1036
+ extraPages: appId === 0 ? "extraProgramPages" in params && params.extraProgramPages !== void 0 ? params.extraProgramPages : approvalProgram ? calculateExtraProgramPages(approvalProgram, clearStateProgram) : 0 : void 0,
1037
+ numLocalInts: appId === 0 ? "schema" in params ? params.schema?.localInts ?? 0 : 0 : void 0,
1038
+ numLocalByteSlices: appId === 0 ? "schema" in params ? params.schema?.localByteSlices ?? 0 : 0 : void 0,
1039
+ numGlobalInts: appId === 0 ? "schema" in params ? params.schema?.globalInts ?? 0 : 0 : void 0,
1040
+ numGlobalByteSlices: appId === 0 ? "schema" in params ? params.schema?.globalByteSlices ?? 0 : 0 : void 0,
1041
+ method: params.method,
1042
+ signer: includeSigner ? params.signer ? "signer" in params.signer ? params.signer.signer : params.signer : this.getSigner(params.sender) : TransactionComposer.NULL_SIGNER,
1043
+ methodArgs: methodArgs.map((arg) => {
1044
+ if (typeof arg === "object" && "context" in arg) {
1045
+ const { context, ...txnWithSigner } = arg;
1046
+ return txnWithSigner;
1047
+ }
1048
+ return arg;
1049
+ }).reverse(),
1050
+ rejectVersion: params.rejectVersion,
1051
+ note: void 0,
1052
+ lease: void 0,
1053
+ rekeyTo: void 0
1054
+ };
1055
+ const result = this.commonTxnBuildStep((txnParams) => {
1056
+ methodAtc.addMethodCall(txnParams);
1057
+ return methodAtc.buildGroup()[methodAtc.count() - 1].txn;
1058
+ }, params, txnParams);
1059
+ return this.buildAtc(methodAtc).map(({ context: _context, ...txnWithSigner }, idx) => {
1060
+ const maxFee = idx === methodAtc.count() - 1 ? result.context.maxFee : maxFees.get(idx);
1061
+ const context = {
1062
+ ..._context,
1063
+ maxFee
1064
+ };
1065
+ return {
1066
+ ...txnWithSigner,
1067
+ context
1068
+ };
1069
+ });
1070
+ }
1071
+ buildPayment(params, suggestedParams) {
1072
+ return this.commonTxnBuildStep(algosdk.makePaymentTxnWithSuggestedParamsFromObject, params, {
1073
+ sender: params.sender,
1074
+ receiver: params.receiver,
1075
+ amount: params.amount.microAlgo,
1076
+ closeRemainderTo: params.closeRemainderTo,
1077
+ suggestedParams
1078
+ });
1079
+ }
1080
+ buildAssetCreate(params, suggestedParams) {
1081
+ return this.commonTxnBuildStep(algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject, params, {
1082
+ sender: params.sender,
1083
+ total: params.total,
1084
+ decimals: params.decimals ?? 0,
1085
+ assetName: params.assetName,
1086
+ unitName: params.unitName,
1087
+ assetURL: params.url,
1088
+ defaultFrozen: params.defaultFrozen ?? false,
1089
+ assetMetadataHash: typeof params.metadataHash === "string" ? Buffer.from(params.metadataHash, "utf-8") : params.metadataHash,
1090
+ manager: params.manager,
1091
+ reserve: params.reserve,
1092
+ freeze: params.freeze,
1093
+ clawback: params.clawback,
1094
+ suggestedParams
1095
+ });
1096
+ }
1097
+ buildAssetConfig(params, suggestedParams) {
1098
+ return this.commonTxnBuildStep(algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject, params, {
1099
+ sender: params.sender,
1100
+ assetIndex: params.assetId,
1101
+ suggestedParams,
1102
+ manager: params.manager,
1103
+ reserve: params.reserve,
1104
+ freeze: params.freeze,
1105
+ clawback: params.clawback,
1106
+ strictEmptyAddressChecking: false
1107
+ });
1108
+ }
1109
+ buildAssetDestroy(params, suggestedParams) {
1110
+ return this.commonTxnBuildStep(algosdk.makeAssetDestroyTxnWithSuggestedParamsFromObject, params, {
1111
+ sender: params.sender,
1112
+ assetIndex: params.assetId,
1113
+ suggestedParams
1114
+ });
1115
+ }
1116
+ buildAssetFreeze(params, suggestedParams) {
1117
+ return this.commonTxnBuildStep(algosdk.makeAssetFreezeTxnWithSuggestedParamsFromObject, params, {
1118
+ sender: params.sender,
1119
+ assetIndex: params.assetId,
1120
+ freezeTarget: params.account,
1121
+ frozen: params.frozen,
1122
+ suggestedParams
1123
+ });
1124
+ }
1125
+ buildAssetTransfer(params, suggestedParams) {
1126
+ return this.commonTxnBuildStep(algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject, params, {
1127
+ sender: params.sender,
1128
+ receiver: params.receiver,
1129
+ assetIndex: params.assetId,
1130
+ amount: params.amount,
1131
+ suggestedParams,
1132
+ closeRemainderTo: params.closeAssetTo,
1133
+ assetSender: params.clawbackTarget
1134
+ });
1135
+ }
1136
+ async buildAppCall(params, suggestedParams) {
1137
+ const appId = "appId" in params ? params.appId : 0n;
1138
+ const approvalProgram = "approvalProgram" in params ? typeof params.approvalProgram === "string" ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes : params.approvalProgram : void 0;
1139
+ const clearStateProgram = "clearStateProgram" in params ? typeof params.clearStateProgram === "string" ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes : params.clearStateProgram : void 0;
1140
+ const sdkParams = {
1141
+ sender: params.sender,
1142
+ suggestedParams,
1143
+ appArgs: params.args,
1144
+ onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
1145
+ accounts: params.accountReferences,
1146
+ foreignApps: params.appReferences?.map((x) => Number(x)),
1147
+ foreignAssets: params.assetReferences?.map((x) => Number(x)),
1148
+ boxes: params.boxReferences?.map(AppManager.getBoxReference),
1149
+ access: params.accessReferences?.map(getResourceReference),
1150
+ approvalProgram,
1151
+ clearProgram: clearStateProgram,
1152
+ rejectVersion: params.rejectVersion
1153
+ };
1154
+ if (appId === 0n) {
1155
+ if (sdkParams.approvalProgram === void 0 || sdkParams.clearProgram === void 0) throw new Error("approvalProgram and clearStateProgram are required for application creation");
1156
+ return this.commonTxnBuildStep(algosdk.makeApplicationCreateTxnFromObject, params, {
1157
+ ...sdkParams,
1158
+ extraPages: "extraProgramPages" in params && params.extraProgramPages !== void 0 ? params.extraProgramPages : calculateExtraProgramPages(approvalProgram, clearStateProgram),
1159
+ numLocalInts: "schema" in params ? params.schema?.localInts ?? 0 : 0,
1160
+ numLocalByteSlices: "schema" in params ? params.schema?.localByteSlices ?? 0 : 0,
1161
+ numGlobalInts: "schema" in params ? params.schema?.globalInts ?? 0 : 0,
1162
+ numGlobalByteSlices: "schema" in params ? params.schema?.globalByteSlices ?? 0 : 0,
1163
+ approvalProgram,
1164
+ clearProgram: clearStateProgram
1165
+ });
1166
+ } else return this.commonTxnBuildStep(algosdk.makeApplicationCallTxnFromObject, params, {
1167
+ ...sdkParams,
1168
+ appIndex: appId
1169
+ });
1170
+ }
1171
+ buildKeyReg(params, suggestedParams) {
1172
+ if ("voteKey" in params) return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1173
+ sender: params.sender,
1174
+ voteKey: params.voteKey,
1175
+ selectionKey: params.selectionKey,
1176
+ voteFirst: params.voteFirst,
1177
+ voteLast: params.voteLast,
1178
+ voteKeyDilution: params.voteKeyDilution,
1179
+ suggestedParams,
1180
+ nonParticipation: false,
1181
+ stateProofKey: params.stateProofKey
1182
+ });
1183
+ return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1184
+ sender: params.sender,
1185
+ suggestedParams,
1186
+ nonParticipation: params.preventAccountFromEverParticipatingAgain
1187
+ });
1188
+ }
1189
+ /** Builds all transaction types apart from `txnWithSigner`, `atc` and `methodCall` since those ones can have custom signers that need to be retrieved. */
1190
+ async buildTxn(txn, suggestedParams) {
1191
+ switch (txn.type) {
1192
+ case "pay": return [this.buildPayment(txn, suggestedParams)];
1193
+ case "assetCreate": return [this.buildAssetCreate(txn, suggestedParams)];
1194
+ case "appCall": return [await this.buildAppCall(txn, suggestedParams)];
1195
+ case "assetConfig": return [this.buildAssetConfig(txn, suggestedParams)];
1196
+ case "assetDestroy": return [this.buildAssetDestroy(txn, suggestedParams)];
1197
+ case "assetFreeze": return [this.buildAssetFreeze(txn, suggestedParams)];
1198
+ case "assetTransfer": return [this.buildAssetTransfer(txn, suggestedParams)];
1199
+ case "assetOptIn": return [this.buildAssetTransfer({
1200
+ ...txn,
1201
+ receiver: txn.sender,
1202
+ amount: 0n
1203
+ }, suggestedParams)];
1204
+ case "assetOptOut": return [this.buildAssetTransfer({
1205
+ ...txn,
1206
+ receiver: txn.sender,
1207
+ amount: 0n,
1208
+ closeAssetTo: txn.creator
1209
+ }, suggestedParams)];
1210
+ case "keyReg": return [this.buildKeyReg(txn, suggestedParams)];
1211
+ default: throw Error(`Unsupported txn type`);
1212
+ }
1213
+ }
1214
+ async buildTxnWithSigner(txn, suggestedParams) {
1215
+ if (txn.type === "txnWithSigner") return [{
1216
+ ...txn,
1217
+ context: {}
1218
+ }];
1219
+ if (txn.type === "atc") return this.buildAtc(txn.atc);
1220
+ if (txn.type === "methodCall") return await this.buildMethodCall(txn, suggestedParams, true);
1221
+ const signer = txn.signer ? "signer" in txn.signer ? txn.signer.signer : txn.signer : this.getSigner(txn.sender);
1222
+ return (await this.buildTxn(txn, suggestedParams)).map(({ txn, context }) => ({
1223
+ txn,
1224
+ signer,
1225
+ context
1226
+ }));
1227
+ }
1228
+ /**
1229
+ * Compose all of the transactions without signers and return the transaction objects directly along with any ABI method calls.
1230
+ *
1231
+ * @returns The array of built transactions and any corresponding method calls
1232
+ * @example
1233
+ * ```typescript
1234
+ * const { transactions, methodCalls, signers } = await composer.buildTransactions()
1235
+ * ```
1236
+ */
1237
+ async buildTransactions() {
1238
+ const suggestedParams = await this.getSuggestedParams();
1239
+ const transactions = [];
1240
+ const methodCalls = /* @__PURE__ */ new Map();
1241
+ const signers = /* @__PURE__ */ new Map();
1242
+ for (const txn of this.txns) if (![
1243
+ "txnWithSigner",
1244
+ "atc",
1245
+ "methodCall"
1246
+ ].includes(txn.type)) transactions.push(...(await this.buildTxn(txn, suggestedParams)).map((txn) => txn.txn));
1247
+ else (txn.type === "txnWithSigner" ? [txn] : txn.type === "atc" ? this.buildAtc(txn.atc) : txn.type === "methodCall" ? await this.buildMethodCall(txn, suggestedParams, false) : []).forEach((ts) => {
1248
+ transactions.push(ts.txn);
1249
+ const groupIdx = transactions.length - 1;
1250
+ if (ts.signer && ts.signer !== TransactionComposer.NULL_SIGNER) signers.set(groupIdx, ts.signer);
1251
+ if ("context" in ts && ts.context.abiMethod) methodCalls.set(groupIdx, ts.context.abiMethod);
1252
+ });
1253
+ return {
1254
+ transactions,
1255
+ methodCalls,
1256
+ signers
1257
+ };
1258
+ }
1259
+ /**
1260
+ * Get the number of transactions currently added to this composer.
1261
+ * @returns The number of transactions currently added to this composer
1262
+ */
1263
+ async count() {
1264
+ return (await this.buildTransactions()).transactions.length;
1265
+ }
1266
+ /**
1267
+ * Compose all of the transactions in a single atomic transaction group and an atomic transaction composer.
1268
+ *
1269
+ * You can then use the transactions standalone, or use the composer to execute or simulate the transactions.
1270
+ *
1271
+ * Once this method is called, no further transactions will be able to be added.
1272
+ * You can safely call this method multiple times to get the same result.
1273
+ * @returns The built atomic transaction composer, the transactions and any corresponding method calls
1274
+ * @example
1275
+ * ```typescript
1276
+ * const { atc, transactions, methodCalls } = await composer.build()
1277
+ * ```
1278
+ */
1279
+ async build() {
1280
+ if (this.atc.getStatus() === algosdk.AtomicTransactionComposerStatus.BUILDING) {
1281
+ const suggestedParams = await this.getSuggestedParams();
1282
+ const txnWithSigners = [];
1283
+ for (const txn of this.txns) txnWithSigners.push(...await this.buildTxnWithSigner(txn, suggestedParams));
1284
+ const methodCalls = /* @__PURE__ */ new Map();
1285
+ txnWithSigners.forEach(({ context, ...ts }, idx) => {
1286
+ this.atc.addTransaction(ts);
1287
+ if (context.abiMethod) methodCalls.set(idx, context.abiMethod);
1288
+ if (context.maxFee !== void 0) this.txnMaxFees.set(idx, context.maxFee);
1289
+ });
1290
+ this.atc["methodCalls"] = methodCalls;
1291
+ }
1292
+ const transactions = this.atc.buildGroup();
1293
+ return {
1294
+ atc: this.atc,
1295
+ transactions,
1296
+ methodCalls: this.atc["methodCalls"]
1297
+ };
1298
+ }
1299
+ /**
1300
+ * Rebuild the group, discarding any previously built transactions.
1301
+ * This will potentially cause new signers and suggested params to be used if the callbacks return a new value compared to the first build.
1302
+ * @returns The newly built atomic transaction composer and the transactions
1303
+ * @example
1304
+ * ```typescript
1305
+ * const { atc, transactions, methodCalls } = await composer.rebuild()
1306
+ * ```
1307
+ */
1308
+ async rebuild() {
1309
+ this.atc = new algosdk.AtomicTransactionComposer();
1310
+ return await this.build();
1311
+ }
1312
+ /**
1313
+ * Compose the atomic transaction group and send it to the network.
1314
+ * @param params The parameters to control execution with
1315
+ * @returns The execution result
1316
+ * @example
1317
+ * ```typescript
1318
+ * const result = await composer.send()
1319
+ * ```
1320
+ */
1321
+ async send(params) {
1322
+ const group = (await this.build()).transactions;
1323
+ let waitRounds = params?.maxRoundsToWaitForConfirmation;
1324
+ const suggestedParams = waitRounds === void 0 || params?.coverAppCallInnerTransactionFees ? await this.getSuggestedParams() : void 0;
1325
+ if (waitRounds === void 0) {
1326
+ const lastRound = group.reduce((max, txn) => txn.txn.lastValid > max ? txn.txn.lastValid : BigInt(max), 0n);
1327
+ const { firstValid: firstRound } = suggestedParams;
1328
+ waitRounds = Number(BigInt(lastRound) - BigInt(firstRound)) + 1;
1329
+ }
1330
+ try {
1331
+ return await sendAtomicTransactionComposer({
1332
+ atc: this.atc,
1333
+ suppressLog: params?.suppressLog,
1334
+ maxRoundsToWaitForConfirmation: waitRounds,
1335
+ populateAppCallResources: params?.populateAppCallResources,
1336
+ coverAppCallInnerTransactionFees: params?.coverAppCallInnerTransactionFees,
1337
+ additionalAtcContext: params?.coverAppCallInnerTransactionFees ? {
1338
+ maxFees: this.txnMaxFees,
1339
+ suggestedParams
1340
+ } : void 0
1341
+ }, this.algod);
1342
+ } catch (originalError) {
1343
+ throw await this.transformError(originalError);
1344
+ }
1345
+ }
1346
+ /**
1347
+ * @deprecated Use `send` instead.
1348
+ *
1349
+ * Compose the atomic transaction group and send it to the network
1350
+ *
1351
+ * An alias for `composer.send(params)`.
1352
+ * @param params The parameters to control execution with
1353
+ * @returns The execution result
1354
+ */
1355
+ async execute(params) {
1356
+ return this.send(params);
1357
+ }
1358
+ async simulate(options) {
1359
+ const { skipSignatures = false, ...rawOptions } = options ?? {};
1360
+ const atc = skipSignatures ? new AtomicTransactionComposer() : this.atc;
1361
+ if (skipSignatures) {
1362
+ rawOptions.allowEmptySignatures = true;
1363
+ rawOptions.fixSigners = true;
1364
+ const transactions = await this.buildTransactions();
1365
+ for (const txn of transactions.transactions) atc.addTransaction({
1366
+ txn,
1367
+ signer: TransactionComposer.NULL_SIGNER
1368
+ });
1369
+ atc["methodCalls"] = transactions.methodCalls;
1370
+ } else await this.build();
1371
+ const { methodResults, simulateResponse } = await atc.simulate(this.algod, new modelsv2.SimulateRequest({
1372
+ txnGroups: [],
1373
+ ...rawOptions,
1374
+ ...Config.debug ? {
1375
+ allowEmptySignatures: true,
1376
+ fixSigners: true,
1377
+ allowMoreLogging: true,
1378
+ execTraceConfig: new modelsv2.SimulateTraceConfig({
1379
+ enable: true,
1380
+ scratchChange: true,
1381
+ stackChange: true,
1382
+ stateChange: true
1383
+ })
1384
+ } : void 0
1385
+ }));
1386
+ const failedGroup = simulateResponse?.txnGroups[0];
1387
+ if (failedGroup?.failureMessage) {
1388
+ const errorMessage = `Transaction failed at transaction(s) ${failedGroup.failedAt?.join(", ") || "unknown"} in the group. ${failedGroup.failureMessage}`;
1389
+ const error = new Error(errorMessage);
1390
+ if (Config.debug) await Config.events.emitAsync("TxnGroupSimulated", { simulateResponse });
1391
+ throw await this.transformError(error);
1392
+ }
1393
+ if (Config.debug && Config.traceAll) await Config.events.emitAsync("TxnGroupSimulated", { simulateResponse });
1394
+ const transactions = atc.buildGroup().map((t) => t.txn);
1395
+ const methodCalls = [...atc["methodCalls"].values()];
1396
+ return {
1397
+ confirmations: simulateResponse.txnGroups[0].txnResults.map((t) => t.txnResult),
1398
+ transactions,
1399
+ txIds: transactions.map((t) => t.txID()),
1400
+ groupId: Buffer.from(transactions[0].group ?? /* @__PURE__ */ new Uint8Array()).toString("base64"),
1401
+ simulateResponse,
1402
+ returns: methodResults.map((r, i) => getABIReturnValue(r, methodCalls[i].returns.type))
1403
+ };
1404
+ }
1405
+ /**
1406
+ * Create an encoded transaction note that follows the ARC-2 spec.
1407
+ *
1408
+ * https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md
1409
+ * @param note The ARC-2 transaction note data
1410
+ * @returns The binary encoded transaction note
1411
+ */
1412
+ static arc2Note(note) {
1413
+ const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === "string" ? note.data : asJson(note.data)}`;
1414
+ return new TextEncoder().encode(arc2Payload);
1415
+ }
1416
+ };
1481
1417
  /**
1482
- * Returns an `algosdk.TransactionResourceReference` given a `ResourceReference`.
1483
- */
1418
+ * Returns an `algosdk.TransactionResourceReference` given a `ResourceReference`.
1419
+ */
1484
1420
  function getResourceReference(accessReference) {
1485
- return {
1486
- address: typeof accessReference.address === 'string' ? Address.fromString(accessReference.address) : accessReference.address,
1487
- appIndex: accessReference.appId,
1488
- assetIndex: accessReference.assetId,
1489
- holding: accessReference.holding ? getHoldingReference(accessReference.holding) : undefined,
1490
- locals: accessReference.locals ? getLocalsReference(accessReference.locals) : undefined,
1491
- box: accessReference.box ? AppManager.getBoxReference(accessReference.box) : undefined,
1492
- };
1421
+ return {
1422
+ address: typeof accessReference.address === "string" ? Address.fromString(accessReference.address) : accessReference.address,
1423
+ appIndex: accessReference.appId,
1424
+ assetIndex: accessReference.assetId,
1425
+ holding: accessReference.holding ? getHoldingReference(accessReference.holding) : void 0,
1426
+ locals: accessReference.locals ? getLocalsReference(accessReference.locals) : void 0,
1427
+ box: accessReference.box ? AppManager.getBoxReference(accessReference.box) : void 0
1428
+ };
1493
1429
  }
1494
1430
  function getHoldingReference(holdingReference) {
1495
- return {
1496
- assetIndex: holdingReference.assetId,
1497
- address: typeof holdingReference.address === 'string' ? Address.fromString(holdingReference.address) : holdingReference.address,
1498
- };
1431
+ return {
1432
+ assetIndex: holdingReference.assetId,
1433
+ address: typeof holdingReference.address === "string" ? Address.fromString(holdingReference.address) : holdingReference.address
1434
+ };
1499
1435
  }
1500
1436
  function getLocalsReference(localsReference) {
1501
- return {
1502
- appIndex: localsReference.appId,
1503
- address: typeof localsReference.address === 'string' ? Address.fromString(localsReference.address) : localsReference.address,
1504
- };
1437
+ return {
1438
+ appIndex: localsReference.appId,
1439
+ address: typeof localsReference.address === "string" ? Address.fromString(localsReference.address) : localsReference.address
1440
+ };
1505
1441
  }
1506
-
1442
+ //#endregion
1507
1443
  export { MAX_TRANSACTION_GROUP_SIZE, TransactionComposer };
1508
- //# sourceMappingURL=composer.mjs.map
1444
+
1445
+ //# sourceMappingURL=composer.mjs.map