@miden-sdk/miden-sdk 0.13.1 → 0.14.0-alpha

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/README.md CHANGED
@@ -132,61 +132,122 @@ yarn check:wasm-types
132
132
 
133
133
  The following are just a few simple examples to get started. For more details, see the [API Reference](../../docs/typedoc/web-client/README.md).
134
134
 
135
+ ### Quick Start
136
+
137
+ ```typescript
138
+ import { MidenClient, AccountType } from "@miden-sdk/miden-sdk";
139
+
140
+ // 1. Create client (defaults to testnet)
141
+ const client = await MidenClient.create();
142
+
143
+ // 2. Create a wallet and a token (faucet account)
144
+ const wallet = await client.accounts.create();
145
+ const dagToken = await client.accounts.create({
146
+ type: AccountType.FungibleFaucet, symbol: "DAG", decimals: 8, maxSupply: 10_000_000n
147
+ });
148
+
149
+ // 3. Mint tokens
150
+ const mintTxId = await client.transactions.mint({ account: dagToken, to: wallet, amount: 1000n });
151
+ await client.transactions.waitFor(mintTxId.toHex());
152
+
153
+ // 4. Consume the minted note
154
+ await client.transactions.consumeAll({ account: wallet });
155
+
156
+ // 5. Send tokens to another address
157
+ await client.transactions.send({
158
+ account: wallet,
159
+ to: "0xBOB",
160
+ token: dagToken,
161
+ amount: 100n
162
+ });
163
+
164
+ // 6. Check balance
165
+ const balance = await client.accounts.getBalance(wallet, dagToken);
166
+ console.log(`Balance: ${balance}`); // 900n
167
+
168
+ // 7. Cleanup
169
+ client.terminate();
170
+ ```
171
+
135
172
  ### Create a New Wallet
136
173
 
137
174
  ```typescript
138
- import { AccountStorageMode, WebClient } from "@miden-sdk/miden-sdk";
175
+ import { MidenClient, AccountType, AuthScheme } from "@miden-sdk/miden-sdk";
176
+
177
+ const client = await MidenClient.create();
178
+
179
+ // Default wallet (private storage, mutable, Falcon auth)
180
+ const wallet = await client.accounts.create();
181
+
182
+ // Wallet with options
183
+ const wallet2 = await client.accounts.create({
184
+ storage: "public",
185
+ type: AccountType.ImmutableWallet,
186
+ auth: AuthScheme.ECDSA,
187
+ seed: "deterministic"
188
+ });
189
+
190
+ console.log(wallet.id().toString()); // account id as hex
191
+ console.log(wallet.isPublic()); // false
192
+ console.log(wallet.isPrivate()); // true
193
+ console.log(wallet.isFaucet()); // false
194
+ ```
195
+
196
+ ### Create a Faucet
197
+
198
+ ```typescript
199
+ const faucet = await client.accounts.create({
200
+ type: AccountType.FungibleFaucet,
201
+ symbol: "DAG",
202
+ decimals: 8,
203
+ maxSupply: 10_000_000n
204
+ });
205
+
206
+ console.log(faucet.id().toString());
207
+ console.log(faucet.isFaucet()); // true
208
+ ```
209
+
210
+ ### Send Tokens
139
211
 
140
- // Instantiate web client object
141
- const webClient = await WebClient.createClient();
212
+ ```typescript
213
+ const txId = await client.transactions.send({
214
+ account: wallet,
215
+ to: "0xBOB",
216
+ token: dagToken,
217
+ amount: 100n
218
+ });
219
+ ```
142
220
 
143
- // Set up newWallet params
144
- const accountStorageMode = AccountStorageMode.private();
145
- const mutable = true;
221
+ ### Consume Notes
146
222
 
147
- // Create new wallet
148
- const account = await webClient.newWallet(accountStorageMode, mutable);
223
+ ```typescript
224
+ // Sync state to discover new notes
225
+ await client.sync();
149
226
 
150
- console.log(account.id().toString()); // account id as hex
151
- console.log(account.isPublic()); // false
152
- console.log(account.isPrivate()); // true
153
- console.log(account.isNetwork()); // false
154
- console.log(account.isFaucet()); // false
227
+ // Consume all available notes for an account
228
+ const result = await client.transactions.consumeAll({ account: wallet });
229
+ console.log(`Consumed ${result.consumed} notes, ${result.remaining} remaining`);
155
230
  ```
156
231
 
157
- ### Create and Execute a New Consume Transaction
232
+ ### Check Balance
158
233
 
159
- Using https://faucet.testnet.miden.io/, send some public test tokens using the account id logged during the new wallet creation. Consume these tokens like this:
234
+ ```typescript
235
+ const balance = await client.accounts.getBalance(wallet, dagToken);
236
+ console.log(`Balance: ${balance}`);
237
+ ```
238
+
239
+ ### Cleanup
240
+
241
+ When you're finished using a MidenClient instance, call `terminate()` to release its Web Worker:
160
242
 
161
243
  ```typescript
162
- // Once the faucet finishes minting the tokens, you need to call syncState() so the client knows there is a note available to be consumed. In an actual application, this may need to be in a loop to constantly discover claimable notes.
163
- await webClient.syncState();
164
-
165
- // Query the client for consumable notes, and retrieve the id of the new note to be consumed
166
- let consumableNotes = await webClient.getConsumableNotes(account);
167
- const noteToConsume = consumableNotes[0].inputNoteRecord().toNote();
168
-
169
- // Create a consume transaction request object
170
- const consumeTransactionRequest = webClient.newConsumeTransactionRequest([
171
- noteToConsume,
172
- ]);
173
-
174
- // Execute, prove, submit, and apply the transaction in one step
175
- const transactionId = await webClient.submitNewTransaction(
176
- account,
177
- consumeTransactionRequest
178
- );
179
-
180
- // Need to sync state again (in a loop) until the node verifies the transaction
181
- await syncState();
182
-
183
- // Check new account balance
184
- const updatedAccount = await webClient.getAccount(account);
185
- const accountBalance = updatedAccount
186
- .vault()
187
- .getBalance(/* id of remote faucet */)
188
- .toString();
189
- console.log(accountBalance);
244
+ client.terminate();
245
+
246
+ // Or use explicit resource management:
247
+ {
248
+ using client = await MidenClient.create();
249
+ // ... use client ...
250
+ } // client.terminate() called automatically
190
251
  ```
191
252
 
192
253
  ## License