@algorandfoundation/algokit-utils 8.2.0-beta.1 → 8.2.0-beta.3
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.
- package/package.json +3 -2
- package/types/account-manager.d.ts +33 -18
- package/types/account-manager.js +33 -18
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +33 -18
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +5 -0
- package/types/account.js +5 -0
- package/types/account.js.map +1 -1
- package/types/account.mjs +5 -0
- package/types/account.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +103 -70
- package/types/algorand-client-transaction-creator.js +103 -70
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +103 -70
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +107 -20
- package/types/algorand-client-transaction-sender.js +107 -21
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +107 -21
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +108 -24
- package/types/algorand-client.js +107 -23
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +107 -23
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -0
- package/types/amount.js +10 -0
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +10 -0
- package/types/amount.mjs.map +1 -1
- package/types/app-client.d.ts +128 -8
- package/types/app-client.js +131 -8
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +131 -8
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +33 -1
- package/types/app-deployer.js +33 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +33 -1
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +74 -4
- package/types/app-factory.js +74 -4
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +74 -4
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.d.ts +64 -0
- package/types/app-manager.js +64 -0
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +64 -0
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +9 -0
- package/types/app-spec.js +9 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +9 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/asset-manager.d.ts +5 -5
- package/types/asset-manager.js +5 -5
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +5 -5
- package/types/asset-manager.mjs.map +1 -1
- package/types/client-manager.d.ts +79 -18
- package/types/client-manager.js +79 -18
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +79 -18
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +599 -1
- package/types/composer.js +575 -1
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +575 -1
- package/types/composer.mjs.map +1 -1
|
@@ -31,12 +31,21 @@ export declare class AlgorandClient {
|
|
|
31
31
|
* Sets the default validity window for transactions.
|
|
32
32
|
* @param validityWindow The number of rounds between the first and last valid rounds
|
|
33
33
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);
|
|
37
|
+
* ```
|
|
34
38
|
*/
|
|
35
39
|
setDefaultValidityWindow(validityWindow: number | bigint): this;
|
|
36
40
|
/**
|
|
37
41
|
* Sets the default signer to use if no other signer is specified.
|
|
38
42
|
* @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
|
|
39
43
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const signer = new SigningAccount(account, account.addr)
|
|
47
|
+
* const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)
|
|
48
|
+
* ```
|
|
40
49
|
*/
|
|
41
50
|
setDefaultSigner(signer: algosdk.TransactionSigner | TransactionSignerAccount): AlgorandClient;
|
|
42
51
|
/**
|
|
@@ -45,21 +54,26 @@ export declare class AlgorandClient {
|
|
|
45
54
|
* a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
|
|
46
55
|
* @example
|
|
47
56
|
* ```typescript
|
|
48
|
-
* const accountManager = AlgorandClient.
|
|
57
|
+
* const accountManager = AlgorandClient.mainNet()
|
|
49
58
|
* .setSignerFromAccount(algosdk.generateAccount())
|
|
50
59
|
* .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
|
|
51
|
-
* .setSignerFromAccount(new SigningAccount(
|
|
60
|
+
* .setSignerFromAccount(new SigningAccount(account, sender))
|
|
52
61
|
* .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
|
|
53
62
|
* .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
|
|
54
63
|
* ```
|
|
55
64
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
56
65
|
*/
|
|
57
|
-
setSignerFromAccount(account: TransactionSignerAccount |
|
|
66
|
+
setSignerFromAccount(account: TransactionSignerAccount | Account | LogicSigAccount | SigningAccount | MultisigAccount): this;
|
|
58
67
|
/**
|
|
59
68
|
* Tracks the given signer against the given sender for later signing.
|
|
60
69
|
* @param sender The sender address to use this signer for
|
|
61
70
|
* @param signer The signer to sign transactions with for the given sender
|
|
62
71
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const signer = new SigningAccount(account, account.addr)
|
|
75
|
+
* const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)
|
|
76
|
+
* ```
|
|
63
77
|
*/
|
|
64
78
|
setSigner(sender: string | Address, signer: algosdk.TransactionSigner): this;
|
|
65
79
|
/**
|
|
@@ -67,59 +81,125 @@ export declare class AlgorandClient {
|
|
|
67
81
|
* @param suggestedParams The suggested params to use
|
|
68
82
|
* @param until A date until which to cache, or if not specified then the timeout is used
|
|
69
83
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))
|
|
87
|
+
* ```
|
|
70
88
|
*/
|
|
71
89
|
setSuggestedParamsCache(suggestedParams: algosdk.SuggestedParams, until?: Date): this;
|
|
72
90
|
/**
|
|
73
91
|
* Sets the timeout for caching suggested params.
|
|
74
92
|
* @param timeout The timeout in milliseconds
|
|
75
93
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)
|
|
97
|
+
* ```
|
|
76
98
|
*/
|
|
77
99
|
setSuggestedParamsCacheTimeout(timeout: number): this;
|
|
78
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)
|
|
102
|
+
* @returns The suggested transaction parameters.
|
|
103
|
+
* @example
|
|
104
|
+
* const params = await AlgorandClient.mainNet().getSuggestedParams();
|
|
105
|
+
*/
|
|
79
106
|
getSuggestedParams(): Promise<algosdk.SuggestedParams>;
|
|
80
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Get clients, including algosdk clients and app clients.
|
|
109
|
+
* @returns The `ClientManager` instance.
|
|
110
|
+
* @example
|
|
111
|
+
* const clientManager = AlgorandClient.mainNet().client;
|
|
112
|
+
*/
|
|
81
113
|
get client(): ClientManager;
|
|
82
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Get or create accounts that can sign transactions.
|
|
116
|
+
* @returns The `AccountManager` instance.
|
|
117
|
+
* @example
|
|
118
|
+
* const accountManager = AlgorandClient.mainNet().account;
|
|
119
|
+
*/
|
|
83
120
|
get account(): AccountManager;
|
|
84
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Methods for interacting with assets.
|
|
123
|
+
* @returns The `AssetManager` instance.
|
|
124
|
+
* @example
|
|
125
|
+
* const assetManager = AlgorandClient.mainNet().asset;
|
|
126
|
+
*/
|
|
85
127
|
get asset(): AssetManager;
|
|
86
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Methods for interacting with apps.
|
|
130
|
+
* @returns The `AppManager` instance.
|
|
131
|
+
* @example
|
|
132
|
+
* const appManager = AlgorandClient.mainNet().app;
|
|
133
|
+
*/
|
|
87
134
|
get app(): AppManager;
|
|
88
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Methods for deploying apps and managing app deployment metadata.
|
|
137
|
+
* @returns The `AppDeployer` instance.
|
|
138
|
+
* @example
|
|
139
|
+
* const deployer = AlgorandClient.mainNet().appDeployer;
|
|
140
|
+
*/
|
|
89
141
|
get appDeployer(): AppDeployer;
|
|
90
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* Start a new `TransactionComposer` transaction group
|
|
144
|
+
* @returns A new instance of `TransactionComposer`.
|
|
145
|
+
* @example
|
|
146
|
+
* const composer = AlgorandClient.mainNet().newGroup();
|
|
147
|
+
* const result = await composer.addTransaction(payment).send()
|
|
148
|
+
*/
|
|
91
149
|
newGroup(): TransactionComposer;
|
|
92
150
|
/**
|
|
93
151
|
* Methods for sending a transaction.
|
|
152
|
+
* @returns The `AlgorandClientTransactionSender` instance.
|
|
153
|
+
* @example
|
|
154
|
+
* const result = await AlgorandClient.mainNet().send.payment({
|
|
155
|
+
* sender: "SENDERADDRESS",
|
|
156
|
+
* receiver: "RECEIVERADDRESS",
|
|
157
|
+
* amount: algo(1)
|
|
158
|
+
* })
|
|
94
159
|
*/
|
|
95
160
|
get send(): AlgorandClientTransactionSender;
|
|
96
161
|
/**
|
|
97
162
|
* Methods for creating a transaction.
|
|
163
|
+
* @returns The `AlgorandClientTransactionCreator` instance.
|
|
164
|
+
* @example
|
|
165
|
+
* const payment = await AlgorandClient.mainNet().createTransaction.payment({
|
|
166
|
+
* sender: "SENDERADDRESS",
|
|
167
|
+
* receiver: "RECEIVERADDRESS",
|
|
168
|
+
* amount: algo(1)
|
|
169
|
+
* })
|
|
98
170
|
*/
|
|
99
171
|
get createTransaction(): AlgorandClientTransactionCreator;
|
|
100
172
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @returns
|
|
173
|
+
* Creates an `AlgorandClient` pointing at default LocalNet ports and API token.
|
|
174
|
+
* @returns An instance of the `AlgorandClient`.
|
|
175
|
+
* @example
|
|
176
|
+
* const algorand = AlgorandClient.defaultLocalNet();
|
|
103
177
|
*/
|
|
104
178
|
static defaultLocalNet(): AlgorandClient;
|
|
105
179
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @returns
|
|
180
|
+
* Creates an `AlgorandClient` pointing at TestNet using AlgoNode.
|
|
181
|
+
* @returns An instance of the `AlgorandClient`.
|
|
182
|
+
* @example
|
|
183
|
+
* const algorand = AlgorandClient.testNet();
|
|
108
184
|
*/
|
|
109
185
|
static testNet(): AlgorandClient;
|
|
110
186
|
/**
|
|
111
|
-
*
|
|
112
|
-
* @returns
|
|
187
|
+
* Creates an `AlgorandClient` pointing at MainNet using AlgoNode.
|
|
188
|
+
* @returns An instance of the `AlgorandClient`.
|
|
189
|
+
* @example
|
|
190
|
+
* const algorand = AlgorandClient.mainNet();
|
|
113
191
|
*/
|
|
114
192
|
static mainNet(): AlgorandClient;
|
|
115
193
|
/**
|
|
116
|
-
*
|
|
117
|
-
* @param clients The clients to use
|
|
118
|
-
* @returns
|
|
194
|
+
* Creates an `AlgorandClient` pointing to the given client(s).
|
|
195
|
+
* @param clients The clients to use.
|
|
196
|
+
* @returns An instance of the `AlgorandClient`.
|
|
197
|
+
* @example
|
|
198
|
+
* const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });
|
|
119
199
|
*/
|
|
120
200
|
static fromClients(clients: AlgoSdkClients): AlgorandClient;
|
|
121
201
|
/**
|
|
122
|
-
*
|
|
202
|
+
* Creates an `AlgorandClient` loading the configuration from environment variables.
|
|
123
203
|
*
|
|
124
204
|
* Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.
|
|
125
205
|
*
|
|
@@ -133,13 +213,17 @@ export declare class AlgorandClient {
|
|
|
133
213
|
*
|
|
134
214
|
* It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
|
|
135
215
|
* otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
|
|
136
|
-
* @returns
|
|
216
|
+
* @returns An instance of the `AlgorandClient`.
|
|
217
|
+
* @example
|
|
218
|
+
* const client = AlgorandClient.fromEnvironment();
|
|
137
219
|
*/
|
|
138
220
|
static fromEnvironment(): AlgorandClient;
|
|
139
221
|
/**
|
|
140
|
-
*
|
|
141
|
-
* @param config The config to use
|
|
142
|
-
* @returns
|
|
222
|
+
* Creates an `AlgorandClient` from the given config.
|
|
223
|
+
* @param config The config to use.
|
|
224
|
+
* @returns An instance of the `AlgorandClient`.
|
|
225
|
+
* @example
|
|
226
|
+
* const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });
|
|
143
227
|
*/
|
|
144
228
|
static fromConfig(config: AlgoConfig): AlgorandClient;
|
|
145
229
|
}
|
package/types/algorand-client.js
CHANGED
|
@@ -28,6 +28,10 @@ class AlgorandClient {
|
|
|
28
28
|
* Sets the default validity window for transactions.
|
|
29
29
|
* @param validityWindow The number of rounds between the first and last valid rounds
|
|
30
30
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);
|
|
34
|
+
* ```
|
|
31
35
|
*/
|
|
32
36
|
setDefaultValidityWindow(validityWindow) {
|
|
33
37
|
this._defaultValidityWindow = BigInt(validityWindow);
|
|
@@ -37,6 +41,11 @@ class AlgorandClient {
|
|
|
37
41
|
* Sets the default signer to use if no other signer is specified.
|
|
38
42
|
* @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
|
|
39
43
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const signer = new SigningAccount(account, account.addr)
|
|
47
|
+
* const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)
|
|
48
|
+
* ```
|
|
40
49
|
*/
|
|
41
50
|
setDefaultSigner(signer) {
|
|
42
51
|
this._accountManager.setDefaultSigner(signer);
|
|
@@ -48,10 +57,10 @@ class AlgorandClient {
|
|
|
48
57
|
* a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
|
|
49
58
|
* @example
|
|
50
59
|
* ```typescript
|
|
51
|
-
* const accountManager = AlgorandClient.
|
|
60
|
+
* const accountManager = AlgorandClient.mainNet()
|
|
52
61
|
* .setSignerFromAccount(algosdk.generateAccount())
|
|
53
62
|
* .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
|
|
54
|
-
* .setSignerFromAccount(new SigningAccount(
|
|
63
|
+
* .setSignerFromAccount(new SigningAccount(account, sender))
|
|
55
64
|
* .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
|
|
56
65
|
* .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
|
|
57
66
|
* ```
|
|
@@ -66,6 +75,11 @@ class AlgorandClient {
|
|
|
66
75
|
* @param sender The sender address to use this signer for
|
|
67
76
|
* @param signer The signer to sign transactions with for the given sender
|
|
68
77
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const signer = new SigningAccount(account, account.addr)
|
|
81
|
+
* const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)
|
|
82
|
+
* ```
|
|
69
83
|
*/
|
|
70
84
|
setSigner(sender, signer) {
|
|
71
85
|
this._accountManager.setSigner(sender, signer);
|
|
@@ -76,6 +90,10 @@ class AlgorandClient {
|
|
|
76
90
|
* @param suggestedParams The suggested params to use
|
|
77
91
|
* @param until A date until which to cache, or if not specified then the timeout is used
|
|
78
92
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))
|
|
96
|
+
* ```
|
|
79
97
|
*/
|
|
80
98
|
setSuggestedParamsCache(suggestedParams, until) {
|
|
81
99
|
this._cachedSuggestedParams = suggestedParams;
|
|
@@ -86,12 +104,21 @@ class AlgorandClient {
|
|
|
86
104
|
* Sets the timeout for caching suggested params.
|
|
87
105
|
* @param timeout The timeout in milliseconds
|
|
88
106
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)
|
|
110
|
+
* ```
|
|
89
111
|
*/
|
|
90
112
|
setSuggestedParamsCacheTimeout(timeout) {
|
|
91
113
|
this._cachedSuggestedParamsTimeout = timeout;
|
|
92
114
|
return this;
|
|
93
115
|
}
|
|
94
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)
|
|
118
|
+
* @returns The suggested transaction parameters.
|
|
119
|
+
* @example
|
|
120
|
+
* const params = await AlgorandClient.mainNet().getSuggestedParams();
|
|
121
|
+
*/
|
|
95
122
|
async getSuggestedParams() {
|
|
96
123
|
if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {
|
|
97
124
|
return {
|
|
@@ -104,27 +131,58 @@ class AlgorandClient {
|
|
|
104
131
|
...this._cachedSuggestedParams,
|
|
105
132
|
};
|
|
106
133
|
}
|
|
107
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Get clients, including algosdk clients and app clients.
|
|
136
|
+
* @returns The `ClientManager` instance.
|
|
137
|
+
* @example
|
|
138
|
+
* const clientManager = AlgorandClient.mainNet().client;
|
|
139
|
+
*/
|
|
108
140
|
get client() {
|
|
109
141
|
return this._clientManager;
|
|
110
142
|
}
|
|
111
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Get or create accounts that can sign transactions.
|
|
145
|
+
* @returns The `AccountManager` instance.
|
|
146
|
+
* @example
|
|
147
|
+
* const accountManager = AlgorandClient.mainNet().account;
|
|
148
|
+
*/
|
|
112
149
|
get account() {
|
|
113
150
|
return this._accountManager;
|
|
114
151
|
}
|
|
115
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* Methods for interacting with assets.
|
|
154
|
+
* @returns The `AssetManager` instance.
|
|
155
|
+
* @example
|
|
156
|
+
* const assetManager = AlgorandClient.mainNet().asset;
|
|
157
|
+
*/
|
|
116
158
|
get asset() {
|
|
117
159
|
return this._assetManager;
|
|
118
160
|
}
|
|
119
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Methods for interacting with apps.
|
|
163
|
+
* @returns The `AppManager` instance.
|
|
164
|
+
* @example
|
|
165
|
+
* const appManager = AlgorandClient.mainNet().app;
|
|
166
|
+
*/
|
|
120
167
|
get app() {
|
|
121
168
|
return this._appManager;
|
|
122
169
|
}
|
|
123
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Methods for deploying apps and managing app deployment metadata.
|
|
172
|
+
* @returns The `AppDeployer` instance.
|
|
173
|
+
* @example
|
|
174
|
+
* const deployer = AlgorandClient.mainNet().appDeployer;
|
|
175
|
+
*/
|
|
124
176
|
get appDeployer() {
|
|
125
177
|
return this._appDeployer;
|
|
126
178
|
}
|
|
127
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Start a new `TransactionComposer` transaction group
|
|
181
|
+
* @returns A new instance of `TransactionComposer`.
|
|
182
|
+
* @example
|
|
183
|
+
* const composer = AlgorandClient.mainNet().newGroup();
|
|
184
|
+
* const result = await composer.addTransaction(payment).send()
|
|
185
|
+
*/
|
|
128
186
|
newGroup() {
|
|
129
187
|
return new types_composer.TransactionComposer({
|
|
130
188
|
algod: this.client.algod,
|
|
@@ -136,20 +194,36 @@ class AlgorandClient {
|
|
|
136
194
|
}
|
|
137
195
|
/**
|
|
138
196
|
* Methods for sending a transaction.
|
|
197
|
+
* @returns The `AlgorandClientTransactionSender` instance.
|
|
198
|
+
* @example
|
|
199
|
+
* const result = await AlgorandClient.mainNet().send.payment({
|
|
200
|
+
* sender: "SENDERADDRESS",
|
|
201
|
+
* receiver: "RECEIVERADDRESS",
|
|
202
|
+
* amount: algo(1)
|
|
203
|
+
* })
|
|
139
204
|
*/
|
|
140
205
|
get send() {
|
|
141
206
|
return this._transactionSender;
|
|
142
207
|
}
|
|
143
208
|
/**
|
|
144
209
|
* Methods for creating a transaction.
|
|
210
|
+
* @returns The `AlgorandClientTransactionCreator` instance.
|
|
211
|
+
* @example
|
|
212
|
+
* const payment = await AlgorandClient.mainNet().createTransaction.payment({
|
|
213
|
+
* sender: "SENDERADDRESS",
|
|
214
|
+
* receiver: "RECEIVERADDRESS",
|
|
215
|
+
* amount: algo(1)
|
|
216
|
+
* })
|
|
145
217
|
*/
|
|
146
218
|
get createTransaction() {
|
|
147
219
|
return this._transactionCreator;
|
|
148
220
|
}
|
|
149
221
|
// Static methods to create an `AlgorandClient`
|
|
150
222
|
/**
|
|
151
|
-
*
|
|
152
|
-
* @returns
|
|
223
|
+
* Creates an `AlgorandClient` pointing at default LocalNet ports and API token.
|
|
224
|
+
* @returns An instance of the `AlgorandClient`.
|
|
225
|
+
* @example
|
|
226
|
+
* const algorand = AlgorandClient.defaultLocalNet();
|
|
153
227
|
*/
|
|
154
228
|
static defaultLocalNet() {
|
|
155
229
|
return new AlgorandClient({
|
|
@@ -159,8 +233,10 @@ class AlgorandClient {
|
|
|
159
233
|
});
|
|
160
234
|
}
|
|
161
235
|
/**
|
|
162
|
-
*
|
|
163
|
-
* @returns
|
|
236
|
+
* Creates an `AlgorandClient` pointing at TestNet using AlgoNode.
|
|
237
|
+
* @returns An instance of the `AlgorandClient`.
|
|
238
|
+
* @example
|
|
239
|
+
* const algorand = AlgorandClient.testNet();
|
|
164
240
|
*/
|
|
165
241
|
static testNet() {
|
|
166
242
|
return new AlgorandClient({
|
|
@@ -170,8 +246,10 @@ class AlgorandClient {
|
|
|
170
246
|
});
|
|
171
247
|
}
|
|
172
248
|
/**
|
|
173
|
-
*
|
|
174
|
-
* @returns
|
|
249
|
+
* Creates an `AlgorandClient` pointing at MainNet using AlgoNode.
|
|
250
|
+
* @returns An instance of the `AlgorandClient`.
|
|
251
|
+
* @example
|
|
252
|
+
* const algorand = AlgorandClient.mainNet();
|
|
175
253
|
*/
|
|
176
254
|
static mainNet() {
|
|
177
255
|
return new AlgorandClient({
|
|
@@ -181,15 +259,17 @@ class AlgorandClient {
|
|
|
181
259
|
});
|
|
182
260
|
}
|
|
183
261
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @param clients The clients to use
|
|
186
|
-
* @returns
|
|
262
|
+
* Creates an `AlgorandClient` pointing to the given client(s).
|
|
263
|
+
* @param clients The clients to use.
|
|
264
|
+
* @returns An instance of the `AlgorandClient`.
|
|
265
|
+
* @example
|
|
266
|
+
* const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });
|
|
187
267
|
*/
|
|
188
268
|
static fromClients(clients) {
|
|
189
269
|
return new AlgorandClient(clients);
|
|
190
270
|
}
|
|
191
271
|
/**
|
|
192
|
-
*
|
|
272
|
+
* Creates an `AlgorandClient` loading the configuration from environment variables.
|
|
193
273
|
*
|
|
194
274
|
* Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.
|
|
195
275
|
*
|
|
@@ -203,15 +283,19 @@ class AlgorandClient {
|
|
|
203
283
|
*
|
|
204
284
|
* It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
|
|
205
285
|
* otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
|
|
206
|
-
* @returns
|
|
286
|
+
* @returns An instance of the `AlgorandClient`.
|
|
287
|
+
* @example
|
|
288
|
+
* const client = AlgorandClient.fromEnvironment();
|
|
207
289
|
*/
|
|
208
290
|
static fromEnvironment() {
|
|
209
291
|
return new AlgorandClient(types_clientManager.ClientManager.getConfigFromEnvironmentOrLocalNet());
|
|
210
292
|
}
|
|
211
293
|
/**
|
|
212
|
-
*
|
|
213
|
-
* @param config The config to use
|
|
214
|
-
* @returns
|
|
294
|
+
* Creates an `AlgorandClient` from the given config.
|
|
295
|
+
* @param config The config to use.
|
|
296
|
+
* @returns An instance of the `AlgorandClient`.
|
|
297
|
+
* @example
|
|
298
|
+
* const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });
|
|
215
299
|
*/
|
|
216
300
|
static fromConfig(config) {
|
|
217
301
|
return new AlgorandClient(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algorand-client.js","sources":["../../src/types/algorand-client.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account'\nimport { AccountManager } from './account-manager'\nimport { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport { AppDeployer } from './app-deployer'\nimport { AppManager } from './app-manager'\nimport { AssetManager } from './asset-manager'\nimport { AlgoSdkClients, ClientManager } from './client-manager'\nimport { TransactionComposer } from './composer'\nimport { AlgoConfig } from './network-client'\nimport Account = algosdk.Account\nimport LogicSigAccount = algosdk.LogicSigAccount\n\n/**\n * A client that brokers easy access to Algorand functionality.\n */\nexport class AlgorandClient {\n private _clientManager: ClientManager\n private _accountManager: AccountManager\n private _appManager: AppManager\n private _appDeployer: AppDeployer\n private _assetManager: AssetManager\n private _transactionSender: AlgorandClientTransactionSender\n private _transactionCreator: AlgorandClientTransactionCreator\n\n private _cachedSuggestedParams?: algosdk.SuggestedParams\n private _cachedSuggestedParamsExpiry?: Date\n private _cachedSuggestedParamsTimeout: number = 3_000 // three seconds\n\n private _defaultValidityWindow: bigint | undefined = undefined\n\n private constructor(config: AlgoConfig | AlgoSdkClients) {\n this._clientManager = new ClientManager(config, this)\n this._accountManager = new AccountManager(this._clientManager)\n this._appManager = new AppManager(this._clientManager.algod)\n this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup())\n this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager, this._appManager)\n this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup())\n this._appDeployer = new AppDeployer(this._appManager, this._transactionSender, this._clientManager.indexerIfPresent)\n }\n\n /**\n * Sets the default validity window for transactions.\n * @param validityWindow The number of rounds between the first and last valid rounds\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setDefaultValidityWindow(validityWindow: number | bigint) {\n this._defaultValidityWindow = BigInt(validityWindow)\n return this\n }\n\n /**\n * Sets the default signer to use if no other signer is specified.\n * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setDefaultSigner(signer: algosdk.TransactionSigner | TransactionSignerAccount): AlgorandClient {\n this._accountManager.setDefaultSigner(signer)\n return this\n }\n\n /**\n * Tracks the given account (object that encapsulates an address and a signer) for later signing.\n * @param account The account to register, which can be a `TransactionSignerAccount` or\n * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`\n * @example\n * ```typescript\n * const accountManager = AlgorandClient.mainnet()\n * .setSignerFromAccount(algosdk.generateAccount())\n * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))\n * .setSignerFromAccount(new SigningAccount(mnemonic, sender))\n * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: [\"ADDRESS1...\", \"ADDRESS2...\"]}, [account1, account2]))\n * .setSignerFromAccount({addr: \"SENDERADDRESS\", signer: transactionSigner})\n * ```\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSignerFromAccount(\n account: TransactionSignerAccount | TransactionSignerAccount | Account | LogicSigAccount | SigningAccount | MultisigAccount,\n ) {\n this._accountManager.setSignerFromAccount(account)\n return this\n }\n\n /**\n * Tracks the given signer against the given sender for later signing.\n * @param sender The sender address to use this signer for\n * @param signer The signer to sign transactions with for the given sender\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSigner(sender: string | Address, signer: algosdk.TransactionSigner) {\n this._accountManager.setSigner(sender, signer)\n return this\n }\n\n /**\n * Sets a cache value to use for suggested transaction params.\n * @param suggestedParams The suggested params to use\n * @param until A date until which to cache, or if not specified then the timeout is used\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSuggestedParamsCache(suggestedParams: algosdk.SuggestedParams, until?: Date) {\n this._cachedSuggestedParams = suggestedParams\n this._cachedSuggestedParamsExpiry = until ?? new Date(+new Date() + this._cachedSuggestedParamsTimeout)\n return this\n }\n\n /**\n * Sets the timeout for caching suggested params.\n * @param timeout The timeout in milliseconds\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSuggestedParamsCacheTimeout(timeout: number) {\n this._cachedSuggestedParamsTimeout = timeout\n return this\n }\n\n /** Get suggested params for a transaction (either cached or from algod if the cache is stale or empty) */\n public async getSuggestedParams(): Promise<algosdk.SuggestedParams> {\n if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n this._cachedSuggestedParams = await this._clientManager.algod.getTransactionParams().do()\n this._cachedSuggestedParamsExpiry = new Date(new Date().getTime() + this._cachedSuggestedParamsTimeout)\n\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n /** Get clients, including algosdk clients and app clients. */\n public get client() {\n return this._clientManager\n }\n\n /** Get or create accounts that can sign transactions. */\n public get account() {\n return this._accountManager\n }\n\n /** Methods for interacting with assets. */\n public get asset() {\n return this._assetManager\n }\n\n /** Methods for interacting with apps. */\n public get app() {\n return this._appManager\n }\n\n /** Methods for deploying apps and managing app deployment metadata. */\n public get appDeployer() {\n return this._appDeployer\n }\n\n /** Start a new `TransactionComposer` transaction group */\n public newGroup() {\n return new TransactionComposer({\n algod: this.client.algod,\n getSigner: (addr: string | Address) => this.account.getSigner(addr),\n getSuggestedParams: () => this.getSuggestedParams(),\n defaultValidityWindow: this._defaultValidityWindow,\n appManager: this._appManager,\n })\n }\n\n /**\n * Methods for sending a transaction.\n */\n public get send() {\n return this._transactionSender\n }\n\n /**\n * Methods for creating a transaction.\n */\n public get createTransaction() {\n return this._transactionCreator\n }\n\n // Static methods to create an `AlgorandClient`\n\n /**\n * Returns an `AlgorandClient` pointing at default LocalNet ports and API token.\n * @returns The `AlgorandClient`\n */\n public static defaultLocalNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getDefaultLocalNetConfig('algod'),\n indexerConfig: ClientManager.getDefaultLocalNetConfig('indexer'),\n kmdConfig: ClientManager.getDefaultLocalNetConfig('kmd'),\n })\n }\n\n /**\n * Returns an `AlgorandClient` pointing at TestNet using AlgoNode.\n * @returns The `AlgorandClient`\n */\n public static testNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('testnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('testnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Returns an `AlgorandClient` pointing at MainNet using AlgoNode.\n * @returns The `AlgorandClient`\n */\n public static mainNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('mainnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('mainnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Returns an `AlgorandClient` pointing to the given client(s).\n * @param clients The clients to use\n * @returns The `AlgorandClient`\n */\n public static fromClients(clients: AlgoSdkClients) {\n return new AlgorandClient(clients)\n }\n\n /**\n * Returns an `AlgorandClient` loading the configuration from environment variables.\n *\n * Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.\n *\n * Expects to be called from a Node.js environment.\n *\n * If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n *\n * If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n *\n * If either aren't defined it will use the default LocalNet config.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @returns The `AlgorandClient`\n */\n public static fromEnvironment() {\n return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet())\n }\n\n /**\n * Returns an `AlgorandClient` from the given config.\n * @param config The config to use\n * @returns The `AlgorandClient`\n */\n public static fromConfig(config: AlgoConfig) {\n return new AlgorandClient(config)\n }\n}\n"],"names":["ClientManager","AccountManager","AppManager","AssetManager","AlgorandClientTransactionSender","AlgorandClientTransactionCreator","AppDeployer","TransactionComposer"],"mappings":";;;;;;;;;;;AAcA;;AAEG;MACU,cAAc,CAAA;AAezB,IAAA,WAAA,CAAoB,MAAmC,EAAA;AAJ/C,QAAA,IAAA,CAAA,6BAA6B,GAAW,IAAK,CAAA;QAE7C,IAAsB,CAAA,sBAAA,GAAuB,SAAS;QAG5D,IAAI,CAAC,cAAc,GAAG,IAAIA,iCAAa,CAAC,MAAM,EAAE,IAAI,CAAC;QACrD,IAAI,CAAC,eAAe,GAAG,IAAIC,mCAAc,CAAC,IAAI,CAAC,cAAc,CAAC;AAC9D,QAAA,IAAI,CAAC,WAAW,GAAG,IAAIC,2BAAU,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,IAAIC,+BAAY,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK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AgBG;AACI,IAAA,OAAO,eAAe,GAAA;QAC3B,OAAO,IAAI,cAAc,CAACA,iCAAa,CAAC,kCAAkC,EAAE,CAAC;;AAG/E;;;;AAIG;IACI,OAAO,UAAU,CAAC,MAAkB,EAAA;AACzC,QAAA,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC;;AAEpC;;;;"}
|
|
1
|
+
{"version":3,"file":"algorand-client.js","sources":["../../src/types/algorand-client.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account'\nimport { AccountManager } from './account-manager'\nimport { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport { AppDeployer } from './app-deployer'\nimport { AppManager } from './app-manager'\nimport { AssetManager } from './asset-manager'\nimport { AlgoSdkClients, ClientManager } from './client-manager'\nimport { TransactionComposer } from './composer'\nimport { AlgoConfig } from './network-client'\nimport Account = algosdk.Account\nimport LogicSigAccount = algosdk.LogicSigAccount\n\n/**\n * A client that brokers easy access to Algorand functionality.\n */\nexport class AlgorandClient {\n private _clientManager: ClientManager\n private _accountManager: AccountManager\n private _appManager: AppManager\n private _appDeployer: AppDeployer\n private _assetManager: AssetManager\n private _transactionSender: AlgorandClientTransactionSender\n private _transactionCreator: AlgorandClientTransactionCreator\n\n private _cachedSuggestedParams?: algosdk.SuggestedParams\n private _cachedSuggestedParamsExpiry?: Date\n private _cachedSuggestedParamsTimeout: number = 3_000 // three seconds\n\n private _defaultValidityWindow: bigint | undefined = undefined\n\n private constructor(config: AlgoConfig | AlgoSdkClients) {\n this._clientManager = new ClientManager(config, this)\n this._accountManager = new AccountManager(this._clientManager)\n this._appManager = new AppManager(this._clientManager.algod)\n this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup())\n this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager, this._appManager)\n this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup())\n this._appDeployer = new AppDeployer(this._appManager, this._transactionSender, this._clientManager.indexerIfPresent)\n }\n\n /**\n * Sets the default validity window for transactions.\n * @param validityWindow The number of rounds between the first and last valid rounds\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);\n * ```\n */\n public setDefaultValidityWindow(validityWindow: number | bigint) {\n this._defaultValidityWindow = BigInt(validityWindow)\n return this\n }\n\n /**\n * Sets the default signer to use if no other signer is specified.\n * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const signer = new SigningAccount(account, account.addr)\n * const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)\n * ```\n */\n public setDefaultSigner(signer: algosdk.TransactionSigner | TransactionSignerAccount): AlgorandClient {\n this._accountManager.setDefaultSigner(signer)\n return this\n }\n\n /**\n * Tracks the given account (object that encapsulates an address and a signer) for later signing.\n * @param account The account to register, which can be a `TransactionSignerAccount` or\n * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`\n * @example\n * ```typescript\n * const accountManager = AlgorandClient.mainNet()\n * .setSignerFromAccount(algosdk.generateAccount())\n * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))\n * .setSignerFromAccount(new SigningAccount(account, sender))\n * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: [\"ADDRESS1...\", \"ADDRESS2...\"]}, [account1, account2]))\n * .setSignerFromAccount({addr: \"SENDERADDRESS\", signer: transactionSigner})\n * ```\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSignerFromAccount(account: TransactionSignerAccount | Account | LogicSigAccount | SigningAccount | MultisigAccount) {\n this._accountManager.setSignerFromAccount(account)\n return this\n }\n\n /**\n * Tracks the given signer against the given sender for later signing.\n * @param sender The sender address to use this signer for\n * @param signer The signer to sign transactions with for the given sender\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const signer = new SigningAccount(account, account.addr)\n * const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)\n * ```\n */\n public setSigner(sender: string | Address, signer: algosdk.TransactionSigner) {\n this._accountManager.setSigner(sender, signer)\n return this\n }\n\n /**\n * Sets a cache value to use for suggested transaction params.\n * @param suggestedParams The suggested params to use\n * @param until A date until which to cache, or if not specified then the timeout is used\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))\n * ```\n */\n public setSuggestedParamsCache(suggestedParams: algosdk.SuggestedParams, until?: Date) {\n this._cachedSuggestedParams = suggestedParams\n this._cachedSuggestedParamsExpiry = until ?? new Date(+new Date() + this._cachedSuggestedParamsTimeout)\n return this\n }\n\n /**\n * Sets the timeout for caching suggested params.\n * @param timeout The timeout in milliseconds\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)\n * ```\n */\n public setSuggestedParamsCacheTimeout(timeout: number) {\n this._cachedSuggestedParamsTimeout = timeout\n return this\n }\n\n /**\n * Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)\n * @returns The suggested transaction parameters.\n * @example\n * const params = await AlgorandClient.mainNet().getSuggestedParams();\n */\n public async getSuggestedParams(): Promise<algosdk.SuggestedParams> {\n if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n this._cachedSuggestedParams = await this._clientManager.algod.getTransactionParams().do()\n this._cachedSuggestedParamsExpiry = new Date(new Date().getTime() + this._cachedSuggestedParamsTimeout)\n\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n /**\n * Get clients, including algosdk clients and app clients.\n * @returns The `ClientManager` instance.\n * @example\n * const clientManager = AlgorandClient.mainNet().client;\n */\n public get client() {\n return this._clientManager\n }\n\n /**\n * Get or create accounts that can sign transactions.\n * @returns The `AccountManager` instance.\n * @example\n * const accountManager = AlgorandClient.mainNet().account;\n */\n public get account() {\n return this._accountManager\n }\n\n /**\n * Methods for interacting with assets.\n * @returns The `AssetManager` instance.\n * @example\n * const assetManager = AlgorandClient.mainNet().asset;\n */\n public get asset() {\n return this._assetManager\n }\n\n /**\n * Methods for interacting with apps.\n * @returns The `AppManager` instance.\n * @example\n * const appManager = AlgorandClient.mainNet().app;\n */\n public get app() {\n return this._appManager\n }\n\n /**\n * Methods for deploying apps and managing app deployment metadata.\n * @returns The `AppDeployer` instance.\n * @example\n * const deployer = AlgorandClient.mainNet().appDeployer;\n */\n public get appDeployer() {\n return this._appDeployer\n }\n\n /**\n * Start a new `TransactionComposer` transaction group\n * @returns A new instance of `TransactionComposer`.\n * @example\n * const composer = AlgorandClient.mainNet().newGroup();\n * const result = await composer.addTransaction(payment).send()\n */\n public newGroup() {\n return new TransactionComposer({\n algod: this.client.algod,\n getSigner: (addr: string | Address) => this.account.getSigner(addr),\n getSuggestedParams: () => this.getSuggestedParams(),\n defaultValidityWindow: this._defaultValidityWindow,\n appManager: this._appManager,\n })\n }\n\n /**\n * Methods for sending a transaction.\n * @returns The `AlgorandClientTransactionSender` instance.\n * @example\n * const result = await AlgorandClient.mainNet().send.payment({\n * sender: \"SENDERADDRESS\",\n * receiver: \"RECEIVERADDRESS\",\n * amount: algo(1)\n * })\n */\n public get send() {\n return this._transactionSender\n }\n\n /**\n * Methods for creating a transaction.\n * @returns The `AlgorandClientTransactionCreator` instance.\n * @example\n * const payment = await AlgorandClient.mainNet().createTransaction.payment({\n * sender: \"SENDERADDRESS\",\n * receiver: \"RECEIVERADDRESS\",\n * amount: algo(1)\n * })\n */\n public get createTransaction() {\n return this._transactionCreator\n }\n\n // Static methods to create an `AlgorandClient`\n\n /**\n * Creates an `AlgorandClient` pointing at default LocalNet ports and API token.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.defaultLocalNet();\n */\n public static defaultLocalNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getDefaultLocalNetConfig('algod'),\n indexerConfig: ClientManager.getDefaultLocalNetConfig('indexer'),\n kmdConfig: ClientManager.getDefaultLocalNetConfig('kmd'),\n })\n }\n\n /**\n * Creates an `AlgorandClient` pointing at TestNet using AlgoNode.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.testNet();\n */\n public static testNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('testnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('testnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Creates an `AlgorandClient` pointing at MainNet using AlgoNode.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.mainNet();\n */\n public static mainNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('mainnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('mainnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Creates an `AlgorandClient` pointing to the given client(s).\n * @param clients The clients to use.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });\n */\n public static fromClients(clients: AlgoSdkClients) {\n return new AlgorandClient(clients)\n }\n\n /**\n * Creates an `AlgorandClient` loading the configuration from environment variables.\n *\n * Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.\n *\n * Expects to be called from a Node.js environment.\n *\n * If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n *\n * If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n *\n * If either aren't defined it will use the default LocalNet config.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const client = AlgorandClient.fromEnvironment();\n */\n public static fromEnvironment() {\n return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet())\n }\n\n /**\n * Creates an `AlgorandClient` from the given config.\n * @param config The config to use.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });\n */\n public static fromConfig(config: AlgoConfig) {\n return new AlgorandClient(config)\n }\n}\n"],"names":["ClientManager","AccountManager","AppManager","AssetManager","AlgorandClientTransactionSender","AlgorandClientTransactionCreator","AppDeployer","TransactionComposer"],"mappings":";;;;;;;;;;;AAcA;;AAEG;MACU,cAAc,CAAA;AAezB,IAAA,WAAA,CAAoB,MAAmC,EAAA;AAJ/C,QAAA,IAAA,CAAA,6BAA6B,GAAW,IAAK,CAAA;QAE7C,IAAsB,CAAA,sBAAA,GAAuB,SAAS;QAG5D,IAAI,CAAC,cAAc,GAAG,IAAIA,iCAAa,CAAC,MAAM,EAAE,IAAI,CAAC;QACrD,IAAI,CAAC,eAAe,GAAG,IAAIC,mCAAc,CAAC,IAAI,CAAC,cAAc,CAAC;AAC9D,QAAA,IAAI,CAAC,WAAW,GAAG,IAAIC,2BAAU,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,IAAIC,+BAAY,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvF,IAAI,CAAC,kBAAkB,GAAG,IAAIC,qEAA+B,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC;AAC1H,QAAA,IAAI,CAAC,mBAAmB,GAAG,IAAIC,uEAAgC,CAAC,MAAM,IAAI,CAA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