@miden-sdk/miden-sdk 0.13.2 → 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 +104 -43
- package/dist/{Cargo-e77f9a02.js → Cargo-D064yzd4.js} +7250 -7428
- package/dist/Cargo-D064yzd4.js.map +1 -0
- package/dist/api-types.d.ts +521 -0
- package/dist/assets/miden_client_web.wasm +0 -0
- package/dist/crates/miden_client_web.d.ts +3658 -3312
- package/dist/docs-entry.d.ts +36 -0
- package/dist/index.d.ts +27 -109
- package/dist/index.js +1302 -106
- package/dist/index.js.map +1 -1
- package/dist/wasm.js +1 -1
- package/dist/wasm.js.map +1 -1
- package/dist/workers/{Cargo-e77f9a02-e77f9a02.js → Cargo-D064yzd4-D064yzd4.js} +7250 -7428
- package/dist/workers/Cargo-D064yzd4-D064yzd4.js.map +1 -0
- package/dist/workers/assets/miden_client_web.wasm +0 -0
- package/dist/workers/web-client-methods-worker.js +43 -45
- package/dist/workers/web-client-methods-worker.js.map +1 -1
- package/package.json +15 -3
- package/dist/Cargo-e77f9a02.js.map +0 -1
- package/dist/workers/Cargo-e77f9a02-e77f9a02.js.map +0 -1
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 {
|
|
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
|
-
|
|
141
|
-
const
|
|
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
|
-
|
|
144
|
-
const accountStorageMode = AccountStorageMode.private();
|
|
145
|
-
const mutable = true;
|
|
221
|
+
### Consume Notes
|
|
146
222
|
|
|
147
|
-
|
|
148
|
-
|
|
223
|
+
```typescript
|
|
224
|
+
// Sync state to discover new notes
|
|
225
|
+
await client.sync();
|
|
149
226
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
console.log(
|
|
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
|
-
###
|
|
232
|
+
### Check Balance
|
|
158
233
|
|
|
159
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|