@algorandfoundation/algokit-utils 1.0.0-beta.8 → 1.0.0-beta.9

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 (68) hide show
  1. package/account.d.ts +87 -0
  2. package/account.d.ts.map +1 -0
  3. package/account.js +144 -0
  4. package/account.js.map +1 -0
  5. package/algo-amount.d.ts +18 -0
  6. package/algo-amount.d.ts.map +1 -0
  7. package/algo-amount.js +31 -0
  8. package/algo-amount.js.map +1 -0
  9. package/algo-http-client-with-retry.d.ts +14 -0
  10. package/algo-http-client-with-retry.d.ts.map +1 -0
  11. package/algo-http-client-with-retry.js +62 -0
  12. package/algo-http-client-with-retry.js.map +1 -0
  13. package/app.d.ts +189 -0
  14. package/app.d.ts.map +1 -0
  15. package/app.js +265 -0
  16. package/app.js.map +1 -0
  17. package/application-client.d.ts +113 -0
  18. package/application-client.d.ts.map +1 -0
  19. package/application-client.js +258 -0
  20. package/application-client.js.map +1 -0
  21. package/config.d.ts +27 -0
  22. package/config.d.ts.map +1 -0
  23. package/config.js +46 -0
  24. package/config.js.map +1 -0
  25. package/deploy-app.d.ts +164 -0
  26. package/deploy-app.d.ts.map +1 -0
  27. package/deploy-app.js +419 -0
  28. package/deploy-app.js.map +1 -0
  29. package/index.d.ts +12 -0
  30. package/index.d.ts.map +1 -0
  31. package/index.js.map +1 -0
  32. package/indexer-lookup.d.ts +31 -0
  33. package/indexer-lookup.d.ts.map +1 -0
  34. package/indexer-lookup.js +96 -0
  35. package/indexer-lookup.js.map +1 -0
  36. package/localnet.d.ts +54 -0
  37. package/localnet.d.ts.map +1 -0
  38. package/localnet.js +121 -0
  39. package/localnet.js.map +1 -0
  40. package/network-client.d.ts +102 -0
  41. package/network-client.d.ts.map +1 -0
  42. package/network-client.js +182 -0
  43. package/network-client.js.map +1 -0
  44. package/package.json +2 -2
  45. package/transaction.d.ts +157 -0
  46. package/transaction.d.ts.map +1 -0
  47. package/transaction.js +306 -0
  48. package/transaction.js.map +1 -0
  49. package/transfer.d.ts +24 -0
  50. package/transfer.d.ts.map +1 -0
  51. package/transfer.js +33 -0
  52. package/transfer.js.map +1 -0
  53. package/types/algod.d.ts +124 -0
  54. package/types/algod.d.ts.map +1 -0
  55. package/types/algod.js +3 -0
  56. package/types/algod.js.map +1 -0
  57. package/types/appspec.d.ts +78 -0
  58. package/types/appspec.d.ts.map +1 -0
  59. package/types/appspec.js +15 -0
  60. package/types/appspec.js.map +1 -0
  61. package/types/indexer.d.ts +314 -0
  62. package/types/indexer.d.ts.map +1 -0
  63. package/types/indexer.js +25 -0
  64. package/types/indexer.js.map +1 -0
  65. package/urlTokenBaseHTTPClient.d.ts +41 -0
  66. package/urlTokenBaseHTTPClient.d.ts.map +1 -0
  67. package/urlTokenBaseHTTPClient.js +151 -0
  68. package/urlTokenBaseHTTPClient.js.map +1 -0
package/localnet.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { Account, Algodv2, Kmd } from 'algosdk';
2
+ import { AlgoAmount } from './algo-amount';
3
+ /** Returns true if the algod client is pointing to a LocalNet Algorand network */
4
+ export declare function isLocalNet(algod: Algodv2): Promise<boolean>;
5
+ /**
6
+ * Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
7
+ *
8
+ * This is useful to get idempotent accounts from a local sandbox without having to specify the private key (which will change when resetting the sandbox).
9
+ *
10
+ * This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh sandbox.
11
+ *
12
+ * If this is used via @see {getAccount}, then you can even use the same code that runs on production without changes for local development!
13
+ *
14
+ * @param walletAccount The wallet details with:
15
+ * * `name`: The name of the wallet to retrieve / create
16
+ * * `fundWith`: The number of Algos to fund the account with it it gets created, if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
17
+ * @param algod An algod client
18
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
19
+ *
20
+ * @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
21
+ */
22
+ export declare function getOrCreateKmdWalletAccount(walletAccount: {
23
+ name: string;
24
+ fundWith?: AlgoAmount;
25
+ }, algod: Algodv2, kmdClient?: Kmd): Promise<Account>;
26
+ /**
27
+ * Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
28
+ *
29
+ * @param walletAccount The details of the wallet, with:
30
+ * * `name`: The name of the wallet to retrieve an account from
31
+ * * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
32
+ * @param algod An algod client
33
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
34
+ * @example Get default funded account in a LocalNet
35
+ *
36
+ * ```
37
+ * const defaultDispenserAccount = await getKmdWalletAccount(algod,
38
+ * 'unencrypted-default-wallet',
39
+ * a => a.status !== 'Offline' && a.amount > 1_000_000_000
40
+ * )
41
+ * ```
42
+ */
43
+ export declare function getKmdWalletAccount(walletAccount: {
44
+ name: string;
45
+ predicate?: (account: Record<string, any>) => boolean;
46
+ }, algod: Algodv2, kmdClient?: Kmd): Promise<Account | undefined>;
47
+ /**
48
+ * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
49
+ *
50
+ * @param algod An algod client
51
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
52
+ */
53
+ export declare function getLocalNetDispenserAccount(algod: Algodv2, kmdClient?: Kmd): Promise<Account>;
54
+ //# sourceMappingURL=localnet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localnet.d.ts","sourceRoot":"","sources":["../src/localnet.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAK1C,kFAAkF;AAClF,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAIjE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,2BAA2B,CAC/C,aAAa,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,EACtD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,CAAC,CAmClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,aAAa,EAAE;IACb,IAAI,EAAE,MAAM,CAAA;IAEZ,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAA;CACtD,EACD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAmC9B;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAWnG"}
package/localnet.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLocalNetDispenserAccount = exports.getKmdWalletAccount = exports.getOrCreateKmdWalletAccount = exports.isLocalNet = void 0;
7
+ const algosdk_1 = __importDefault(require("algosdk"));
8
+ const account_1 = require("./account");
9
+ const algo_amount_1 = require("./algo-amount");
10
+ const config_1 = require("./config");
11
+ const network_client_1 = require("./network-client");
12
+ const transfer_1 = require("./transfer");
13
+ /** Returns true if the algod client is pointing to a LocalNet Algorand network */
14
+ async function isLocalNet(algod) {
15
+ const params = await algod.getTransactionParams().do();
16
+ return params.genesisID === 'devnet-v1' || params.genesisID === 'sandnet-v1';
17
+ }
18
+ exports.isLocalNet = isLocalNet;
19
+ /**
20
+ * Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
21
+ *
22
+ * This is useful to get idempotent accounts from a local sandbox without having to specify the private key (which will change when resetting the sandbox).
23
+ *
24
+ * This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh sandbox.
25
+ *
26
+ * If this is used via @see {getAccount}, then you can even use the same code that runs on production without changes for local development!
27
+ *
28
+ * @param walletAccount The wallet details with:
29
+ * * `name`: The name of the wallet to retrieve / create
30
+ * * `fundWith`: The number of Algos to fund the account with it it gets created, if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
31
+ * @param algod An algod client
32
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
33
+ *
34
+ * @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
35
+ */
36
+ async function getOrCreateKmdWalletAccount(walletAccount, algod, kmdClient) {
37
+ const kmd = kmdClient ?? (0, network_client_1.getAlgoKmdClient)();
38
+ // Get an existing account from the KMD wallet
39
+ const existing = await getKmdWalletAccount(walletAccount, algod, kmd);
40
+ if (existing) {
41
+ return existing;
42
+ }
43
+ // None existed: create the KMD wallet instead
44
+ const walletId = (await kmd.createWallet(walletAccount.name, '')).wallet.id;
45
+ const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
46
+ await kmd.generateKey(walletHandle);
47
+ // Get the account from the new KMD wallet
48
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
+ const account = (await getKmdWalletAccount(walletAccount, algod, kmd));
50
+ config_1.AlgoKitConfig.logger.info(`Couldn't find existing account in Sandbox under name '${walletAccount.name}'; created account ${account.addr} with keys stored in KMD and funding with ${walletAccount.fundWith?.algos ?? 1000} ALGOs`);
51
+ // Fund the account from the dispenser
52
+ await (0, transfer_1.transferAlgos)({
53
+ amount: walletAccount.fundWith ?? algo_amount_1.AlgoAmount.Algos(1000),
54
+ from: await (0, account_1.getDispenserAccount)(algod),
55
+ to: account.addr,
56
+ }, algod);
57
+ return account;
58
+ }
59
+ exports.getOrCreateKmdWalletAccount = getOrCreateKmdWalletAccount;
60
+ /**
61
+ * Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
62
+ *
63
+ * @param walletAccount The details of the wallet, with:
64
+ * * `name`: The name of the wallet to retrieve an account from
65
+ * * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
66
+ * @param algod An algod client
67
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
68
+ * @example Get default funded account in a LocalNet
69
+ *
70
+ * ```
71
+ * const defaultDispenserAccount = await getKmdWalletAccount(algod,
72
+ * 'unencrypted-default-wallet',
73
+ * a => a.status !== 'Offline' && a.amount > 1_000_000_000
74
+ * )
75
+ * ```
76
+ */
77
+ async function getKmdWalletAccount(walletAccount, algod, kmdClient) {
78
+ const { name, predicate } = walletAccount;
79
+ const kmd = kmdClient ?? (0, network_client_1.getAlgoKmdClient)();
80
+ const wallets = await kmd.listWallets();
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ const wallet = wallets.wallets.filter((w) => w.name === name);
83
+ if (wallet.length === 0) {
84
+ return undefined;
85
+ }
86
+ const walletId = wallet[0].id;
87
+ const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
88
+ const keyIds = (await kmd.listKeys(walletHandle)).addresses;
89
+ let i = 0;
90
+ if (predicate) {
91
+ for (i = 0; i < keyIds.length; i++) {
92
+ const key = keyIds[i];
93
+ const account = await algod.accountInformation(key).do();
94
+ if (predicate(account)) {
95
+ break;
96
+ }
97
+ }
98
+ }
99
+ if (i >= keyIds.length) {
100
+ return undefined;
101
+ }
102
+ const accountKey = (await kmd.exportKey(walletHandle, '', keyIds[i])).private_key;
103
+ const accountMnemonic = algosdk_1.default.secretKeyToMnemonic(accountKey);
104
+ return (0, account_1.getAccountFromMnemonic)(accountMnemonic);
105
+ }
106
+ exports.getKmdWalletAccount = getKmdWalletAccount;
107
+ /**
108
+ * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
109
+ *
110
+ * @param algod An algod client
111
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
112
+ */
113
+ async function getLocalNetDispenserAccount(algod, kmdClient) {
114
+ if (!(await isLocalNet(algod))) {
115
+ throw "Can't get default account from non LocalNet network";
116
+ }
117
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
+ return (await getKmdWalletAccount({ name: 'unencrypted-default-wallet', predicate: (a) => a.status !== 'Offline' && a.amount > 1000000000 }, algod, kmdClient));
119
+ }
120
+ exports.getLocalNetDispenserAccount = getLocalNetDispenserAccount;
121
+ //# sourceMappingURL=localnet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localnet.js","sourceRoot":"","sources":["../src/localnet.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwD;AACxD,uCAAuE;AACvE,+CAA0C;AAC1C,qCAAwC;AACxC,qDAAmD;AACnD,yCAA0C;AAE1C,kFAAkF;AAC3E,KAAK,UAAU,UAAU,CAAC,KAAc;IAC7C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE,CAAA;IAEtD,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,KAAK,YAAY,CAAA;AAC9E,CAAC;AAJD,gCAIC;AAED;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,2BAA2B,CAC/C,aAAsD,EACtD,KAAc,EACd,SAAe;IAEf,MAAM,GAAG,GAAG,SAAS,IAAI,IAAA,iCAAgB,GAAE,CAAA;IAE3C,8CAA8C;IAC9C,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,aAAa,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;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CD,kDA2CC;AAED;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAAC,KAAc,EAAE,SAAe;IAC/E,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE;QAC9B,MAAM,qDAAqD,CAAA;KAC5D;IAED,oEAAoE;IACpE,OAAO,CAAC,MAAM,mBAAmB,CAC/B,EAAE,IAAI,EAAE,4BAA4B,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,GAAG,UAAa,EAAE,EAC5G,KAAK,EACL,SAAS,CACV,CAAE,CAAA;AACL,CAAC;AAXD,kEAWC"}
@@ -0,0 +1,102 @@
1
+ import { Algodv2, Indexer, Kmd } from 'algosdk';
2
+ import { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient';
3
+ /** Config for an Algorand SDK client */
4
+ export interface AlgoClientConfig {
5
+ /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */
6
+ server: string;
7
+ /** The port to use e.g. 4001, 443, etc. */
8
+ port?: string | number;
9
+ /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */
10
+ token?: string | TokenHeader;
11
+ }
12
+ /** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
13
+ export declare function getAlgodConfigFromEnvironment(): AlgoClientConfig;
14
+ /** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
15
+ export declare function getIndexerConfigFromEnvironment(): AlgoClientConfig;
16
+ /** Returns the Algorand configuration to point to the AlgoNode service
17
+ *
18
+ * @param network Which network to connect to - TestNet or MainNet
19
+ * @param config Which algod config to return - Algod or Indexer
20
+ */
21
+ export declare function getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig;
22
+ /** Returns the Algorand configuration to point to the default LocalNet
23
+ *
24
+ * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
25
+ */
26
+ export declare function getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig;
27
+ /** Returns an algod SDK client that automatically retries on idempotent calls
28
+ *
29
+ * @param config The config if you want to override the default (getting config from process.env)
30
+ * @example Default (load from environment variables)
31
+ *
32
+ * ```
33
+ * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
34
+ * // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
35
+ * const algod = getAlgoClient()
36
+ * await algod.healthCheck().do()
37
+ * ```
38
+ * @example AlgoNode (testnet)
39
+ * ```
40
+ * const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
41
+ * await algod.healthCheck().do()
42
+ * ```
43
+ * @example AlgoNode (mainnet)
44
+ * ```
45
+ * const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
46
+ * await algod.healthCheck().do()
47
+ * ```
48
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
49
+ * ```
50
+ * const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
51
+ * await algod.healthCheck().do()
52
+ * ```
53
+ */
54
+ export declare function getAlgoClient(config?: AlgoClientConfig): Algodv2;
55
+ /** Returns an indexer SDK client that automatically retries on idempotent calls
56
+ *
57
+ * @param config The config if you want to override the default (getting config from process.env)
58
+ * @example Default (load from environment variables)
59
+ *
60
+ * ```
61
+ * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
62
+ * // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
63
+ * const indexer = getAlgoIndexerClient()
64
+ * await indexer.makeHealthCheck().do()
65
+ * ```
66
+ * @example AlgoNode (testnet)
67
+ * ```
68
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
69
+ * await indexer.makeHealthCheck().do()
70
+ * ```
71
+ * @example AlgoNode (mainnet)
72
+ * ```
73
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
74
+ * await indexer.makeHealthCheck().do()
75
+ * ```
76
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
77
+ * ```
78
+ * const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
79
+ * await indexer.makeHealthCheck().do()
80
+ * ```
81
+ */
82
+ export declare function getAlgoIndexerClient(config?: AlgoClientConfig): Indexer;
83
+ /**
84
+ * Returns a KMD SDK client that automatically retries on idempotent calls
85
+ *
86
+ * KMD client allows you to export private keys, which is useful to get the default account in a sandbox network.
87
+ *
88
+ * @param config The config if you want to override the default (getting config from process.env)
89
+ * @example Default (load from environment variables)
90
+ *
91
+ * ```
92
+ * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
93
+ * const kmd = getAlgoKmdClient()
94
+ * ```
95
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
96
+ * ```
97
+ * const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
98
+ * ```
99
+ */
100
+ export declare function getAlgoKmdClient(config?: AlgoClientConfig): Kmd;
101
+ export { isLocalNet } from './localnet';
102
+ //# sourceMappingURL=network-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-client.d.ts","sourceRoot":"","sources":["../src/network-client.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAG9E,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,yIAAyI;IACzI,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;CAC7B;AAED,mIAAmI;AACnI,wBAAgB,6BAA6B,IAAI,gBAAgB,CAchE;AAED,qIAAqI;AACrI,wBAAgB,+BAA+B,IAAI,gBAAgB,CAclE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,CAK/G;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,gBAAgB,CAM7G;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAIhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAIvE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,GAAG,CAK/D;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.isLocalNet = exports.getAlgoKmdClient = exports.getAlgoIndexerClient = exports.getAlgoClient = exports.getDefaultLocalNetConfig = exports.getAlgoNodeConfig = exports.getIndexerConfigFromEnvironment = exports.getAlgodConfigFromEnvironment = void 0;
27
+ const algosdk_1 = __importStar(require("algosdk"));
28
+ const algo_http_client_with_retry_1 = require("./algo-http-client-with-retry");
29
+ /** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
30
+ function getAlgodConfigFromEnvironment() {
31
+ if (!process || !process.env) {
32
+ throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
33
+ }
34
+ if (!process.env.ALGOD_SERVER) {
35
+ throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables');
36
+ }
37
+ return {
38
+ server: process.env.ALGOD_SERVER,
39
+ port: process.env.ALGOD_PORT,
40
+ token: process.env.ALGOD_TOKEN,
41
+ };
42
+ }
43
+ exports.getAlgodConfigFromEnvironment = getAlgodConfigFromEnvironment;
44
+ /** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
45
+ function getIndexerConfigFromEnvironment() {
46
+ if (!process || !process.env) {
47
+ throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead');
48
+ }
49
+ if (!process.env.INDEXER_SERVER) {
50
+ throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables');
51
+ }
52
+ return {
53
+ server: process.env.INDEXER_SERVER,
54
+ port: process.env.INDEXER_PORT,
55
+ token: process.env.INDEXER_TOKEN,
56
+ };
57
+ }
58
+ exports.getIndexerConfigFromEnvironment = getIndexerConfigFromEnvironment;
59
+ /** Returns the Algorand configuration to point to the AlgoNode service
60
+ *
61
+ * @param network Which network to connect to - TestNet or MainNet
62
+ * @param config Which algod config to return - Algod or Indexer
63
+ */
64
+ function getAlgoNodeConfig(network, config) {
65
+ return {
66
+ server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,
67
+ port: 443,
68
+ };
69
+ }
70
+ exports.getAlgoNodeConfig = getAlgoNodeConfig;
71
+ /** Returns the Algorand configuration to point to the default LocalNet
72
+ *
73
+ * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
74
+ */
75
+ function getDefaultLocalNetConfig(configOrPort) {
76
+ return {
77
+ server: `http://localhost`,
78
+ port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,
79
+ token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
80
+ };
81
+ }
82
+ exports.getDefaultLocalNetConfig = getDefaultLocalNetConfig;
83
+ function getAlgoTokenHeader(server, token, defaultHeader) {
84
+ // Purestake uses a slightly different API key header than the default
85
+ if (server.includes('purestake.io') && typeof token === 'string')
86
+ return { 'X-API-Key': token };
87
+ // Because we override the default HTTP Client construction (to get retries) we need to put a string token into the standard header ourselves
88
+ return typeof token === 'string' ? { [defaultHeader ?? 'X-Algo-API-Token']: token } : token ?? {};
89
+ }
90
+ /** Returns an algod SDK client that automatically retries on idempotent calls
91
+ *
92
+ * @param config The config if you want to override the default (getting config from process.env)
93
+ * @example Default (load from environment variables)
94
+ *
95
+ * ```
96
+ * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
97
+ * // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
98
+ * const algod = getAlgoClient()
99
+ * await algod.healthCheck().do()
100
+ * ```
101
+ * @example AlgoNode (testnet)
102
+ * ```
103
+ * const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
104
+ * await algod.healthCheck().do()
105
+ * ```
106
+ * @example AlgoNode (mainnet)
107
+ * ```
108
+ * const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
109
+ * await algod.healthCheck().do()
110
+ * ```
111
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
112
+ * ```
113
+ * const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
114
+ * await algod.healthCheck().do()
115
+ * ```
116
+ */
117
+ function getAlgoClient(config) {
118
+ const { token, server, port } = config ?? getAlgodConfigFromEnvironment();
119
+ const httpClientWithRetry = new algo_http_client_with_retry_1.AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token), server, port);
120
+ return new algosdk_1.default.Algodv2(httpClientWithRetry, server);
121
+ }
122
+ exports.getAlgoClient = getAlgoClient;
123
+ /** Returns an indexer SDK client that automatically retries on idempotent calls
124
+ *
125
+ * @param config The config if you want to override the default (getting config from process.env)
126
+ * @example Default (load from environment variables)
127
+ *
128
+ * ```
129
+ * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
130
+ * // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
131
+ * const indexer = getAlgoIndexerClient()
132
+ * await indexer.makeHealthCheck().do()
133
+ * ```
134
+ * @example AlgoNode (testnet)
135
+ * ```
136
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
137
+ * await indexer.makeHealthCheck().do()
138
+ * ```
139
+ * @example AlgoNode (mainnet)
140
+ * ```
141
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
142
+ * await indexer.makeHealthCheck().do()
143
+ * ```
144
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
145
+ * ```
146
+ * const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
147
+ * await indexer.makeHealthCheck().do()
148
+ * ```
149
+ */
150
+ function getAlgoIndexerClient(config) {
151
+ const { token, server, port } = config ?? getIndexerConfigFromEnvironment();
152
+ const httpClientWithRetry = new algo_http_client_with_retry_1.AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token, 'X-Indexer-API-Token'), server, port);
153
+ return new algosdk_1.Indexer(httpClientWithRetry);
154
+ }
155
+ exports.getAlgoIndexerClient = getAlgoIndexerClient;
156
+ /**
157
+ * Returns a KMD SDK client that automatically retries on idempotent calls
158
+ *
159
+ * KMD client allows you to export private keys, which is useful to get the default account in a sandbox network.
160
+ *
161
+ * @param config The config if you want to override the default (getting config from process.env)
162
+ * @example Default (load from environment variables)
163
+ *
164
+ * ```
165
+ * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
166
+ * const kmd = getAlgoKmdClient()
167
+ * ```
168
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
169
+ * ```
170
+ * const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
171
+ * ```
172
+ */
173
+ function getAlgoKmdClient(config) {
174
+ const { token, server } = config ?? getAlgodConfigFromEnvironment();
175
+ // We can only use Kmd on the Sandbox otherwise it's not exposed so this makes some assumptions
176
+ // (e.g. same token and server as algod and port 4002 by default)
177
+ return new algosdk_1.Kmd(token, server, process?.env?.KMD_PORT ?? '4002');
178
+ }
179
+ exports.getAlgoKmdClient = getAlgoKmdClient;
180
+ var localnet_1 = require("./localnet");
181
+ Object.defineProperty(exports, "isLocalNet", { enumerable: true, get: function () { return localnet_1.isLocalNet; } });
182
+ //# sourceMappingURL=network-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-client.js","sourceRoot":"","sources":["../src/network-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAwD;AAExD,+EAAuE;AAYvE,mIAAmI;AACnI,SAAgB,6BAA6B;IAC3C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAA;KACpH;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,yGAAyG,CAAC,CAAA;KAC3H;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QAChC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;QAC5B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;KAC/B,CAAA;AACH,CAAC;AAdD,sEAcC;AAED,qIAAqI;AACrI,SAAgB,+BAA+B;IAC7C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,oGAAoG,CAAC,CAAA;KACtH;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,6GAA6G,CAAC,CAAA;KAC/H;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAClC,IAAI,EA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MAAM,IAAI,6BAA6B,EAAE,CAAA;IACzE,MAAM,mBAAmB,GAAG,IAAI,qDAAuB,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IACxG,OAAO,IAAI,iBAAO,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;AACzD,CAAC;AAJD,sCAIC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,oBAAoB,CAAC,MAAyB;IAC5D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,+BAA+B,EAAE,CAAA;IAC3E,MAAM,mBAAmB,GAAG,IAAI,qDAAuB,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,qBAAqB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IAC/H,OAAO,IAAI,iBAAO,CAAC,mBAAmB,CAAC,CAAA;AACzC,CAAC;AAJD,oDAIC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,gBAAgB,CAAC,MAAyB;IACxD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,6BAA6B,EAAE,CAAA;IACnE,+FAA+F;IAC/F,iEAAiE;IACjE,OAAO,IAAI,aAAG,CAAC,KAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAA;AAC3E,CAAC;AALD,4CAKC;AAED,uCAAuC;AAA9B,sGAAA,UAAU,OAAA"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "main": "index.js",
3
3
  "types": "index.d.ts",
4
4
  "name": "@algorandfoundation/algokit-utils",
5
- "version": "1.0.0-beta.8",
5
+ "version": "1.0.0-beta.9",
6
6
  "private": false,
7
7
  "description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
8
8
  "author": "Algorand Foundation",
@@ -11,7 +11,7 @@
11
11
  "node": ">=16.0"
12
12
  },
13
13
  "files": [
14
- "dist/**/*"
14
+ "**/*"
15
15
  ],
16
16
  "dependencies": {
17
17
  "algosdk": "^2.1.0",
@@ -0,0 +1,157 @@
1
+ import algosdk, { Account, Algodv2, LogicSigAccount, MultisigMetadata, SuggestedParams, Transaction, TransactionSigner } from 'algosdk';
2
+ import { AlgoAmount } from './algo-amount';
3
+ import { PendingTransactionResponse } from './types/algod';
4
+ /** Account wrapper that supports partial or full multisig signing */
5
+ export declare class MultisigAccount {
6
+ _params: algosdk.MultisigMetadata;
7
+ _signingAccounts: (algosdk.Account | SigningAccount)[];
8
+ _addr: string;
9
+ get params(): Readonly<algosdk.MultisigMetadata>;
10
+ get signingAccounts(): Readonly<(algosdk.Account | SigningAccount)[]>;
11
+ get addr(): Readonly<string>;
12
+ constructor(multisigParams: MultisigMetadata, signingAccounts: (Account | SigningAccount)[]);
13
+ sign(transaction: Transaction | Uint8Array): Uint8Array;
14
+ }
15
+ /** Account wrapper that supports a rekeyed account */
16
+ export declare class SigningAccount implements Account {
17
+ private _account;
18
+ private _sender;
19
+ /**
20
+ * Algorand address of the sender
21
+ */
22
+ get addr(): Readonly<string>;
23
+ /**
24
+ * Secret key belonging to the signer
25
+ */
26
+ get sk(): Readonly<Uint8Array>;
27
+ /**
28
+ * Algorand account of the underlying signing account
29
+ */
30
+ get signer(): Account;
31
+ /**
32
+ * Algorand account of the sender address and signer private key
33
+ */
34
+ get sender(): Account;
35
+ constructor(account: Account, sender: string | undefined);
36
+ }
37
+ /** A wrapper around @see {TransactionSigner} that also has the sender address. */
38
+ export interface TransactionSignerAccount {
39
+ addr: Readonly<string>;
40
+ signer: TransactionSigner;
41
+ }
42
+ export type TransactionNote = Uint8Array | TransactionNoteData | Arc2TransactionNote;
43
+ export type TransactionNoteData = string | null | undefined | number | any[] | Record<string, any>;
44
+ /** ARC-0002 compatible transaction note components, @see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md */
45
+ export type Arc2TransactionNote = {
46
+ dAppName: string;
47
+ format: 'm' | 'j' | 'b' | 'u';
48
+ data: string;
49
+ };
50
+ /** Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
51
+ *
52
+ * @param note The transaction note
53
+ * @returns the transaction note ready for inclusion in a transaction
54
+ *
55
+ * Case on the value of `data` this either either be:
56
+ * * `null` | `undefined`: `undefined`
57
+ * * `string`: The string value
58
+ * * Uint8Array: passthrough
59
+ * * Arc2TransactionNote object: ARC-0002 compatible transaction note
60
+ * * Else: The object/value converted into a JSON string representation
61
+ */
62
+ export declare function encodeTransactionNote(note?: TransactionNote): Uint8Array | undefined;
63
+ /** The sending configuration for a transaction */
64
+ export interface SendTransactionParams {
65
+ /** Whether to skip signing and sending the transaction to the chain (default: transaction signed and sent to chain)
66
+ * (and instead just return the raw transaction, e.g. so you can add it to a group of transactions) */
67
+ skipSending?: boolean;
68
+ /** Whether to skip waiting for the submitted transaction (only relevant if `skipSending` is `false` or unset) */
69
+ skipWaiting?: boolean;
70
+ /** Whether to suppress log messages from transaction send, default: do not suppress */
71
+ suppressLog?: boolean;
72
+ /** The maximum fee that you are happy to pay (default: unbounded) - if this is set it's possible the transaction could get rejected during network congestion */
73
+ maxFee?: AlgoAmount;
74
+ /** The maximum number of rounds to wait for confirmation, only applies if `skipWaiting` is `undefined` or `false`, default: wait up to 5 rounds */
75
+ maxRoundsToWaitForConfirmation?: number;
76
+ }
77
+ /** The result of sending a transaction */
78
+ export interface SendTransactionResult {
79
+ /** The transaction */
80
+ transaction: Transaction;
81
+ /** The response if the transaction was sent and waited for */
82
+ confirmation?: PendingTransactionResponse;
83
+ }
84
+ export type SendTransactionFrom = Account | SigningAccount | LogicSigAccount | MultisigAccount | TransactionSignerAccount;
85
+ /**
86
+ * Returns the public address of the given transaction sender.
87
+ * @param sender A transaction sender
88
+ * @returns The public address
89
+ */
90
+ export declare const getSenderAddress: (sender: SendTransactionFrom) => string;
91
+ /** Signs and sends the given transaction to the chain
92
+ *
93
+ * @param send The details for the transaction to send, including:
94
+ * * `transaction`: The unsigned transaction
95
+ * * `from`: The account to sign the transaction with: either an account with private key loaded or a logic signature account
96
+ * * `config`: The sending configuration for this transaction
97
+ * @param algod An algod client
98
+ *
99
+ * @returns An object with transaction (`transaction`) and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
100
+ */
101
+ export declare const sendTransaction: (send: {
102
+ transaction: Transaction;
103
+ from: SendTransactionFrom;
104
+ sendParams?: SendTransactionParams;
105
+ }, algod: Algodv2) => Promise<SendTransactionResult>;
106
+ /** Defines an unsigned transaction that will appear in a group of transactions along with its signing information */
107
+ export interface TransactionToSign {
108
+ /** The unsigned transaction to sign and send */
109
+ transaction: Transaction;
110
+ /** The account to use to sign the transaction, either an account (with private key loaded) or a logic signature account */
111
+ signer: SendTransactionFrom;
112
+ }
113
+ /**
114
+ * Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-details/atomic_transfers/#create-transactions) transactions to the chain
115
+ *
116
+ * @param groupSend The group details to send, with:
117
+ * * `transactions`: The array of transactions to send along with their signing account
118
+ * * `sendParams`: The parameters to dictate how the group is sent
119
+ * @param algod An algod client
120
+ * @returns An object with group transaction ID (`groupTransactionId`) and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
121
+ */
122
+ export declare const sendGroupOfTransactions: (groupSend: {
123
+ transactions: TransactionToSign[];
124
+ sendParams?: Omit<Omit<SendTransactionParams, 'maxFee'>, 'skipSending'>;
125
+ }, algod: Algodv2) => Promise<{
126
+ groupId: string;
127
+ confirmations: PendingTransactionResponse[] | undefined;
128
+ txIds: string[];
129
+ }>;
130
+ /**
131
+ * Wait until the transaction is confirmed or rejected, or until `timeout`
132
+ * number of rounds have passed.
133
+ *
134
+ * @param algod An algod client
135
+ * @param transactionId The transaction ID to wait for
136
+ * @param maxRoundsToWait Maximum number of rounds to wait
137
+ *
138
+ * @return Pending transaction information
139
+ * @throws Throws an error if the transaction is not confirmed or rejected in the next `timeout` rounds
140
+ */
141
+ export declare const waitForConfirmation: (transactionId: string, maxRoundsToWait: number, algod: Algodv2) => Promise<PendingTransactionResponse>;
142
+ /**
143
+ * Limit the acceptable fee to a defined amount of µALGOs.
144
+ * This also sets the transaction to be flatFee to ensure the transaction only succeeds at
145
+ * the estimated rate.
146
+ * @param transaction The transaction to cap
147
+ * @param maxAcceptableFee The maximum acceptable fee to pay
148
+ */
149
+ export declare function capTransactionFee(transaction: algosdk.Transaction, maxAcceptableFee: AlgoAmount): void;
150
+ /**
151
+ * Returns suggested transaction parameters from algod unless some are already provided.
152
+ * @param params Optionally provide parameters to use
153
+ * @param algod Algod algod
154
+ * @returns The suggested transaction parameters
155
+ */
156
+ export declare function getTransactionParams(params: SuggestedParams | undefined, algod: Algodv2): Promise<algosdk.SuggestedParams>;
157
+ //# sourceMappingURL=transaction.d.ts.map