@tari-project/tarijs 0.10.1 → 0.11.0

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 (71) hide show
  1. package/README.md +127 -67
  2. package/TODO.md +91 -3
  3. package/docusaurus/tari-docs/README.md +200 -17
  4. package/docusaurus/tari-docs/docs/api-reference.md +665 -0
  5. package/docusaurus/tari-docs/docs/contributing.md +619 -0
  6. package/docusaurus/tari-docs/docs/guides/getting-started-tutorial.md +965 -0
  7. package/docusaurus/tari-docs/docs/guides/production-deployment.md +977 -0
  8. package/docusaurus/tari-docs/docs/index.md +114 -11
  9. package/docusaurus/tari-docs/docs/installation.md +142 -1
  10. package/docusaurus/tari-docs/docs/signers/metamask.md +529 -0
  11. package/docusaurus/tari-docs/docs/troubleshooting.md +661 -0
  12. package/docusaurus/tari-docs/package.json +1 -1
  13. package/examples/vite-typescript-react/README.md +9 -0
  14. package/examples/vite-typescript-react/eslint.config.js +23 -0
  15. package/examples/vite-typescript-react/index.html +13 -0
  16. package/examples/vite-typescript-react/package.json +35 -0
  17. package/examples/vite-typescript-react/public/vite.svg +1 -0
  18. package/examples/vite-typescript-react/src/App.css +42 -0
  19. package/examples/vite-typescript-react/src/App.tsx +50 -0
  20. package/examples/vite-typescript-react/src/assets/react.svg +1 -0
  21. package/examples/vite-typescript-react/src/index.css +68 -0
  22. package/examples/vite-typescript-react/src/main.tsx +10 -0
  23. package/examples/vite-typescript-react/src/vite-env.d.ts +1 -0
  24. package/examples/vite-typescript-react/tsconfig.app.json +27 -0
  25. package/examples/vite-typescript-react/tsconfig.json +7 -0
  26. package/examples/vite-typescript-react/tsconfig.node.json +25 -0
  27. package/examples/vite-typescript-react/vite.config.ts +7 -0
  28. package/package.json +2 -2
  29. package/packages/builders/package.json +2 -2
  30. package/packages/builders/src/transaction/TransactionBuilder.ts +4 -12
  31. package/packages/indexer_provider/package.json +2 -2
  32. package/packages/indexer_provider/src/provider.ts +5 -5
  33. package/packages/indexer_provider/tsconfig.json +4 -2
  34. package/packages/metamask_signer/package.json +2 -2
  35. package/packages/metamask_signer/src/index.ts +2 -14
  36. package/packages/{tari_permissions → permissions}/package.json +2 -2
  37. package/packages/{tari_permissions → permissions}/src/helpers.ts +1 -1
  38. package/packages/permissions/src/index.ts +2 -0
  39. package/packages/{tari_permissions/src/tari_permissions.ts → permissions/src/permissions.ts} +56 -6
  40. package/packages/react-mui-connect-button/moon.yml +71 -0
  41. package/packages/react-mui-connect-button/package.json +40 -0
  42. package/packages/react-mui-connect-button/src/Logos.tsx +60 -0
  43. package/packages/react-mui-connect-button/src/TariConnectButton.tsx +51 -0
  44. package/packages/react-mui-connect-button/src/TariWalletSelectionDialog.tsx +116 -0
  45. package/packages/react-mui-connect-button/src/content/tari-logo-white.svg +18 -0
  46. package/packages/react-mui-connect-button/src/content/tari-logo.svg +18 -0
  47. package/packages/react-mui-connect-button/src/content/walletconnect-logo.svg +13 -0
  48. package/packages/react-mui-connect-button/src/defaultPermissions.ts +0 -0
  49. package/packages/react-mui-connect-button/src/index.ts +24 -0
  50. package/packages/react-mui-connect-button/tsconfig.json +31 -0
  51. package/packages/tari_provider/package.json +2 -2
  52. package/packages/tari_signer/package.json +2 -2
  53. package/packages/tari_universe/package.json +2 -2
  54. package/packages/tari_universe/tsconfig.json +4 -2
  55. package/packages/tarijs/package.json +2 -2
  56. package/packages/tarijs/tsconfig.json +4 -2
  57. package/packages/tarijs_types/package.json +2 -2
  58. package/packages/wallet_daemon/package.json +2 -2
  59. package/packages/wallet_daemon/src/provider.ts +8 -6
  60. package/packages/wallet_daemon/src/signer.ts +11 -6
  61. package/packages/wallet_daemon/tsconfig.json +1 -1
  62. package/packages/walletconnect/package.json +3 -2
  63. package/packages/walletconnect/src/index.ts +52 -26
  64. package/packages/walletconnect/tsconfig.json +3 -0
  65. package/pnpm-workspace.yaml +15 -7
  66. package/scripts/check_versions.sh +4 -0
  67. package/scripts/clean_everything.sh +38 -0
  68. package/tsconfig.json +6 -0
  69. package/packages/tari_permissions/src/index.ts +0 -2
  70. /package/packages/{tari_permissions → permissions}/moon.yml +0 -0
  71. /package/packages/{tari_permissions → permissions}/tsconfig.json +0 -0
@@ -0,0 +1,665 @@
1
+ ---
2
+ sidebar_position: 11
3
+ title: API Reference
4
+ ---
5
+
6
+ # API Reference
7
+
8
+ Complete TypeScript API reference for tari.js library. This document covers all public interfaces, classes, and functions.
9
+
10
+ ## Core Interfaces
11
+
12
+ ### TariSigner
13
+
14
+ The `TariSigner` interface defines wallet operations that require authentication and transaction signing.
15
+
16
+ ```typescript
17
+ interface TariSigner {
18
+ signerName: string;
19
+ isConnected(): boolean;
20
+ getAccount(): Promise<AccountData>;
21
+ getSubstate(substate_address: string): Promise<Substate>;
22
+ submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>;
23
+ getTransactionResult(transactionId: string): Promise<GetTransactionResultResponse>;
24
+ getTemplateDefinition(template_address: string): Promise<TemplateDefinition>;
25
+ getPublicKey(branch: string, index: number): Promise<string>;
26
+ getConfidentialVaultBalances(req: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances>;
27
+ listSubstates(req: ListSubstatesRequest): Promise<ListSubstatesResponse>;
28
+ getNftsList(req: ListAccountNftRequest): Promise<ListAccountNftResponse>;
29
+ }
30
+ ```
31
+
32
+ #### Methods
33
+
34
+ ##### `isConnected(): boolean`
35
+ Check if the signer is currently connected to a wallet.
36
+
37
+ **Returns:** `boolean` - True if connected, false otherwise
38
+
39
+ ##### `getAccount(): Promise<AccountData>`
40
+ Get the default account information.
41
+
42
+ **Returns:** `Promise<AccountData>` - Account details including address and metadata
43
+
44
+ **Throws:**
45
+ - `Error` - If no wallet is connected or account retrieval fails
46
+
47
+ ##### `submitTransaction(req: SubmitTransactionRequest): Promise<SubmitTransactionResponse>`
48
+ Submit a transaction to the network.
49
+
50
+ **Parameters:**
51
+ - `req: SubmitTransactionRequest` - Transaction request object
52
+
53
+ **Returns:** `Promise<SubmitTransactionResponse>` - Transaction submission result with ID
54
+
55
+ <!-- VERIFIED: Source packages/builders/src/transaction/TransactionBuilder.ts:130 -->
56
+ **Example:**
57
+ ```typescript
58
+ const transaction = new TransactionBuilder()
59
+ .feeTransactionPayFromComponent(account.address, "100")
60
+ .callMethod({
61
+ componentAddress: account.address,
62
+ methodName: 'withdraw',
63
+ args: [{ type: 'Amount', value: '1000' }]
64
+ }, [])
65
+ .build();
66
+
67
+ const result = await signer.submitTransaction({ transaction });
68
+ console.log('Transaction ID:', result.transaction_id);
69
+ ```
70
+
71
+ ##### `getTransactionResult(transactionId: string): Promise<GetTransactionResultResponse>`
72
+ Get the result of a previously submitted transaction.
73
+
74
+ **Parameters:**
75
+ - `transactionId: string` - Transaction identifier
76
+
77
+ **Returns:** `Promise<GetTransactionResultResponse>` - Transaction execution result
78
+
79
+ ##### `getConfidentialVaultBalances(req: ConfidentialViewVaultBalanceRequest): Promise<VaultBalances>`
80
+ Get confidential vault balances (privacy-preserving).
81
+
82
+ **Parameters:**
83
+ - `req: ConfidentialViewVaultBalanceRequest` - Balance request with view key
84
+
85
+ **Returns:** `Promise<VaultBalances>` - Vault balances with privacy protection
86
+
87
+ ### TariProvider
88
+
89
+ The `TariProvider` interface defines read-only blockchain data access.
90
+
91
+ ```typescript
92
+ interface TariProvider {
93
+ providerName: string;
94
+ isConnected(): boolean;
95
+ getSubstate(req: GetSubstateRequest): Promise<Substate>;
96
+ getTransactionResult(transactionId: string): Promise<GetTransactionResultResponse>;
97
+ getTemplateDefinition(template_address: string): Promise<GetTemplateDefinitionResponse>;
98
+ listSubstates(req: ListSubstatesRequest): Promise<ListSubstatesResponse>;
99
+ listTemplates(limit?: number): Promise<ListTemplatesResponse>;
100
+ }
101
+ ```
102
+
103
+ #### Methods
104
+
105
+ ##### `getSubstate(req: GetSubstateRequest): Promise<Substate>`
106
+ Retrieve a specific substate from the blockchain.
107
+
108
+ **Parameters:**
109
+ - `req: GetSubstateRequest` - Substate query request
110
+
111
+ **Returns:** `Promise<Substate>` - Substate data and metadata
112
+
113
+ <!-- VERIFIED: Source packages/wallet_daemon/src/signer.ts:160 -->
114
+ **Example:**
115
+ ```typescript
116
+ const substate = await signer.getSubstate("component_1234...");
117
+ // Note: TariProvider getSubstate has different signature than TariSigner
118
+ ```
119
+
120
+ ##### `listSubstates(req: ListSubstatesRequest): Promise<ListSubstatesResponse>`
121
+ List substates matching specified criteria.
122
+
123
+ **Parameters:**
124
+ - `req: ListSubstatesRequest` - Query filters and pagination
125
+
126
+ **Returns:** `Promise<ListSubstatesResponse>` - Paginated substate list
127
+
128
+ ##### `listTemplates(limit?: number): Promise<ListTemplatesResponse>`
129
+ List available smart contract templates.
130
+
131
+ **Parameters:**
132
+ - `limit?: number` - Maximum number of templates to return
133
+
134
+ **Returns:** `Promise<ListTemplatesResponse>` - Available template definitions
135
+
136
+ ## Signer Implementations
137
+
138
+ ### WalletDaemonTariSigner
139
+
140
+ Connects to Tari Wallet Daemon via JSON-RPC.
141
+
142
+ ```typescript
143
+ class WalletDaemonTariSigner implements TariSigner {
144
+ constructor(params: WalletDaemonParameters);
145
+ }
146
+
147
+ interface WalletDaemonParameters {
148
+ endpoint: string;
149
+ timeout?: number;
150
+ retryAttempts?: number;
151
+ auth?: {
152
+ username: string;
153
+ password: string;
154
+ };
155
+ }
156
+ ```
157
+
158
+ **Example:**
159
+ <!-- VERIFIED: Source packages/wallet_daemon/src/signer.ts:71 -->
160
+ ```typescript
161
+ const signer = await WalletDaemonTariSigner.buildFetchSigner({
162
+ serverUrl: 'http://localhost:18103',
163
+ permissions: new TariPermissions()
164
+ });
165
+ // Note: No direct constructor - use static build methods
166
+ ```
167
+
168
+ ### MetamaskTariSigner
169
+
170
+ Integrates with MetaMask via the Tari snap.
171
+
172
+ ```typescript
173
+ class MetamaskTariSigner implements TariSigner {
174
+ constructor();
175
+ }
176
+ ```
177
+
178
+ **Prerequisites:**
179
+ - MetaMask Flask installed
180
+ - Tari snap installed and connected
181
+
182
+ **Example:**
183
+ ```typescript
184
+ const signer = new MetamaskTariSigner();
185
+ await signer.connect(); // Triggers MetaMask connection flow
186
+ ```
187
+
188
+ ### TariUniverseSigner
189
+
190
+ Connects to Tari Universe wallet.
191
+
192
+ ```typescript
193
+ class TariUniverseSigner implements TariSigner {
194
+ constructor(params: TariUniverseSignerParameters);
195
+ }
196
+
197
+ interface TariUniverseSignerParameters {
198
+ endpoint?: string;
199
+ timeout?: number;
200
+ network?: Network;
201
+ }
202
+ ```
203
+
204
+ ### WalletConnectTariSigner
205
+
206
+ Integrates with mobile and desktop wallets via WalletConnect.
207
+
208
+ ```typescript
209
+ class WalletConnectTariSigner implements TariSigner {
210
+ constructor(params: WalletConnectParameters);
211
+ }
212
+
213
+ interface WalletConnectParameters {
214
+ projectId: string;
215
+ metadata: {
216
+ name: string;
217
+ description: string;
218
+ url: string;
219
+ icons: string[];
220
+ };
221
+ }
222
+ ```
223
+
224
+ ## Provider Implementations
225
+
226
+ ### IndexerProvider
227
+
228
+ Read-only access to blockchain data via Tari Indexer.
229
+
230
+ ```typescript
231
+ class IndexerProvider implements TariProvider {
232
+ constructor(params: IndexerProviderParameters);
233
+ }
234
+
235
+ interface IndexerProviderParameters {
236
+ endpoint: string;
237
+ timeout?: number;
238
+ maxConnections?: number;
239
+ }
240
+ ```
241
+
242
+ **Example:**
243
+ ```typescript
244
+ const provider = new IndexerProvider({
245
+ endpoint: 'http://localhost:18300',
246
+ timeout: 5000,
247
+ maxConnections: 10
248
+ });
249
+ ```
250
+
251
+ ### WalletDaemonTariProvider
252
+
253
+ Read-only access via Wallet Daemon (useful for consistency with signer).
254
+
255
+ ```typescript
256
+ class WalletDaemonTariProvider implements TariProvider {
257
+ constructor(params: WalletDaemonParameters);
258
+ }
259
+ ```
260
+
261
+ ## Transaction Building
262
+
263
+ ### TransactionBuilder
264
+
265
+ Fluent API for constructing transactions.
266
+
267
+ ```typescript
268
+ class TransactionBuilder {
269
+ constructor(network: number);
270
+
271
+ // Core methods
272
+ fee(amount: number): this;
273
+ inputs(inputs: SubstateRequirement[]): this;
274
+ minEpoch(epoch: number): this;
275
+ maxEpoch(epoch: number): this;
276
+
277
+ // Function calls
278
+ callFunction<T extends TariFunctionDefinition>(
279
+ func: T,
280
+ args: Exclude<T["args"], undefined>
281
+ ): this;
282
+
283
+ // Method calls
284
+ callMethod<T extends TariMethodDefinition>(
285
+ method: T,
286
+ args: Exclude<T["args"], undefined>
287
+ ): this;
288
+
289
+ // Account operations
290
+ createAccount(ownerPublicKey: string, workspaceBucket?: string): this;
291
+ createProof(account: ComponentAddress, resourceAddress: ResourceAddress): this;
292
+
293
+ // Workspace operations
294
+ saveVariable(key: string, workspaceId: string): this;
295
+ claimBurn(claim: ConfidentialClaim): this;
296
+
297
+ // Building
298
+ build(): TransactionRequest;
299
+ }
300
+ ```
301
+
302
+ #### Core Building Methods
303
+
304
+ ##### `feeTransactionPayFromComponent(componentAddress: ComponentAddress, maxFee: string): this`
305
+ Set the transaction fee paid from a component.
306
+
307
+ **Parameters:**
308
+ - `componentAddress: ComponentAddress` - Address of component paying fee
309
+ - `maxFee: string` - Maximum fee amount as string
310
+
311
+ **Returns:** `this` - Builder instance for chaining
312
+
313
+ <!-- VERIFIED: Source packages/builders/src/transaction/TransactionBuilder.ts:85 -->
314
+ **Example:**
315
+ ```typescript
316
+ const transaction = new TransactionBuilder()
317
+ .feeTransactionPayFromComponent(account.address, "100") // 100 Tari fee
318
+ .build();
319
+ ```
320
+
321
+ ##### `inputs(inputs: SubstateRequirement[]): this`
322
+ Specify required inputs for the transaction.
323
+
324
+ **Parameters:**
325
+ - `inputs: SubstateRequirement[]` - Array of required substates
326
+
327
+ **Returns:** `this` - Builder instance for chaining
328
+
329
+ ##### `callFunction(func: TariFunctionDefinition, args: NamedArg[]): this`
330
+ Call a smart contract function.
331
+
332
+ **Parameters:**
333
+ - `func: TariFunctionDefinition` - Function definition
334
+ - `args: NamedArg[]` - Function arguments
335
+
336
+ **Returns:** `this` - Builder instance for chaining
337
+
338
+ <!-- VERIFIED: Source packages/builders/src/transaction/TransactionBuilder.ts:116 -->
339
+ **Example:**
340
+ ```typescript
341
+ const transaction = new TransactionBuilder()
342
+ .feeTransactionPayFromComponent(account.address, "100")
343
+ .callFunction({
344
+ templateAddress: 'template_1234...',
345
+ functionName: 'mint_nft',
346
+ args: [
347
+ { name: 'amount', value: 1 },
348
+ { name: 'metadata', value: { name: 'My NFT' } }
349
+ ]
350
+ }, [])
351
+ .build();
352
+ ```
353
+
354
+ ##### `callMethod(method: TariMethodDefinition, args: TransactionArg[]): this`
355
+ Call a method on an existing component.
356
+
357
+ **Parameters:**
358
+ - `method: TariMethodDefinition` - Method definition
359
+ - `args: TransactionArg[]` - Method arguments
360
+
361
+ **Returns:** `this` - Builder instance for chaining
362
+
363
+ <!-- VERIFIED: Source packages/builders/src/transaction/TransactionBuilder.ts:130 -->
364
+ **Example:**
365
+ ```typescript
366
+ const transaction = new TransactionBuilder()
367
+ .feeTransactionPayFromComponent(account.address, "100")
368
+ .callMethod({
369
+ componentAddress: 'component_1234...',
370
+ methodName: 'withdraw',
371
+ }, [
372
+ { type: 'Amount', value: '1000' }
373
+ ])
374
+ .build();
375
+ ```
376
+
377
+ ##### `createAccount(ownerPublicKey: string, workspaceBucket?: string): this`
378
+ Create a new account.
379
+
380
+ **Parameters:**
381
+ - `ownerPublicKey: string` - Public key of the account owner
382
+ - `workspaceBucket?: string` - Optional workspace bucket name
383
+
384
+ **Returns:** `this` - Builder instance for chaining
385
+
386
+ ##### `saveVariable(key: string, workspaceId: string): this`
387
+ Save a workspace variable for later use.
388
+
389
+ **Parameters:**
390
+ - `key: string` - Variable identifier
391
+ - `workspaceId: string` - Workspace location
392
+
393
+ **Returns:** `this` - Builder instance for chaining
394
+
395
+ ##### `build(): TransactionRequest`
396
+ Build the final transaction request.
397
+
398
+ **Returns:** `TransactionRequest` - Complete transaction ready for submission
399
+
400
+ ## Type Definitions
401
+
402
+ ### Core Types
403
+
404
+ ```typescript
405
+ interface AccountData {
406
+ address: string;
407
+ name?: string;
408
+ public_key: string;
409
+ }
410
+
411
+ interface Substate {
412
+ substate_id: string;
413
+ version: number;
414
+ data: any;
415
+ created_by_transaction: string;
416
+ }
417
+
418
+ interface TemplateDefinition {
419
+ template_address: string;
420
+ binary: Uint8Array;
421
+ functions: FunctionDefinition[];
422
+ }
423
+
424
+ interface VaultBalances {
425
+ balances: Array<{
426
+ resource_address: string;
427
+ balance: number;
428
+ confidential_balance?: ConfidentialBalance;
429
+ }>;
430
+ }
431
+
432
+ enum TransactionStatus {
433
+ Pending = "Pending",
434
+ Accepted = "Accepted",
435
+ Rejected = "Rejected",
436
+ DryRun = "DryRun"
437
+ }
438
+
439
+ enum Network {
440
+ LocalNet = 0,
441
+ Esmeralda = 1,
442
+ MainNet = 2
443
+ }
444
+ ```
445
+
446
+ ### Request/Response Types
447
+
448
+ ```typescript
449
+ interface SubmitTransactionRequest {
450
+ transaction: TransactionRequest;
451
+ is_dry_run?: boolean;
452
+ }
453
+
454
+ interface SubmitTransactionResponse {
455
+ transactionId: string;
456
+ status: TransactionStatus;
457
+ }
458
+
459
+ interface GetTransactionResultResponse {
460
+ transaction_id: string;
461
+ status: TransactionStatus;
462
+ result?: TransactionResult;
463
+ execution_time?: number;
464
+ }
465
+
466
+ interface ListSubstatesRequest {
467
+ filter_by_template?: string;
468
+ filter_by_type?: string;
469
+ limit?: number;
470
+ offset?: number;
471
+ }
472
+
473
+ interface ListSubstatesResponse {
474
+ substates: Substate[];
475
+ total_count: number;
476
+ }
477
+ ```
478
+
479
+ ## Utility Functions
480
+
481
+ ### CBOR Utilities
482
+
483
+ ```typescript
484
+ // Parse CBOR data
485
+ function parseCbor(data: Uint8Array): any;
486
+
487
+ // Get value from CBOR by path
488
+ function getCborValueByPath(data: any, path: string): any;
489
+ ```
490
+
491
+ ### Address Utilities
492
+
493
+ ```typescript
494
+ // Create NFT address from resource
495
+ function createNftAddressFromResource(resourceAddress: string, tokenId: string): string;
496
+
497
+ // Create NFT address from token
498
+ function createNftAddressFromToken(tokenAddress: string): string;
499
+ ```
500
+
501
+ ### Conversion Utilities
502
+
503
+ ```typescript
504
+ // Convert hex string to U256 array
505
+ function convertHexStringToU256Array(hex: string): number[];
506
+
507
+ // Convert U256 to hex string
508
+ function convertU256ToHexString(u256: number[]): string;
509
+
510
+ // Convert string to transaction status
511
+ function convertStringToTransactionStatus(status: string): TransactionStatus;
512
+
513
+ // Hex string utilities
514
+ function fromHexString(hex: string): Uint8Array;
515
+ function toHexString(bytes: Uint8Array): string;
516
+ ```
517
+
518
+ ## Advanced Functions
519
+
520
+ ### Transaction Management
521
+
522
+ ```typescript
523
+ // Build and execute a transaction request
524
+ function buildTransactionRequest(
525
+ builder: TransactionBuilder,
526
+ signer: TariSigner
527
+ ): Promise<TransactionRequest>;
528
+
529
+ // Submit transaction and wait for result
530
+ function submitAndWaitForTransaction(
531
+ signer: TariSigner,
532
+ transaction: TransactionRequest,
533
+ timeout?: number
534
+ ): Promise<GetTransactionResultResponse>;
535
+
536
+ // Wait for transaction result
537
+ function waitForTransactionResult(
538
+ signer: TariSigner,
539
+ transactionId: string,
540
+ timeout?: number
541
+ ): Promise<GetTransactionResultResponse>;
542
+ ```
543
+
544
+ ### Example Usage
545
+
546
+ ```typescript
547
+ <!-- VERIFIED: Combined from actual implementation patterns -->
548
+ // Complete transaction flow
549
+ const builder = new TransactionBuilder()
550
+ .feeTransactionPayFromComponent(account.address, "100")
551
+ .callMethod({
552
+ componentAddress: account.address,
553
+ methodName: 'withdraw',
554
+ }, [
555
+ { type: 'Amount', value: '1000' }
556
+ ]);
557
+
558
+ const transaction = builder.build();
559
+ const result = await signer.submitTransaction({ transaction });
560
+
561
+ if (result.status === TransactionStatus.Accepted) {
562
+ console.log('Transaction successful!');
563
+ } else {
564
+ console.error('Transaction failed:', result);
565
+ }
566
+ ```
567
+
568
+ ## Error Handling
569
+
570
+ ### Common Error Types
571
+
572
+ ```typescript
573
+ // Connection errors
574
+ class ConnectionError extends Error {
575
+ constructor(message: string, public endpoint: string) {
576
+ super(message);
577
+ }
578
+ }
579
+
580
+ // Transaction errors
581
+ class TransactionError extends Error {
582
+ constructor(message: string, public transactionId?: string) {
583
+ super(message);
584
+ }
585
+ }
586
+
587
+ // Validation errors
588
+ class ValidationError extends Error {
589
+ constructor(message: string, public field: string) {
590
+ super(message);
591
+ }
592
+ }
593
+ ```
594
+
595
+ ### Best Practices
596
+
597
+ ```typescript
598
+ // Always wrap wallet operations in try-catch
599
+ try {
600
+ const result = await signer.submitTransaction(transaction);
601
+ console.log('Success:', result);
602
+ } catch (error) {
603
+ if (error instanceof ConnectionError) {
604
+ console.error('Connection failed:', error.endpoint);
605
+ } else if (error instanceof TransactionError) {
606
+ console.error('Transaction failed:', error.transactionId);
607
+ } else {
608
+ console.error('Unexpected error:', error.message);
609
+ }
610
+ }
611
+
612
+ // Check connection status before operations
613
+ if (!signer.isConnected()) {
614
+ throw new Error('Wallet not connected');
615
+ }
616
+
617
+ // Validate inputs before building transactions
618
+ if (amount <= 0) {
619
+ throw new ValidationError('Amount must be positive', 'amount');
620
+ }
621
+ ```
622
+
623
+ ## Performance Optimization
624
+
625
+ ### Connection Pooling
626
+
627
+ ```typescript
628
+ // Use connection pooling for providers
629
+ const provider = new IndexerProvider({
630
+ endpoint: 'http://localhost:18300',
631
+ maxConnections: 10, // Pool size
632
+ timeout: 5000
633
+ });
634
+ ```
635
+
636
+ ### Batch Operations
637
+
638
+ ```typescript
639
+ // Batch substate queries for better performance
640
+ const substateIds = ['id1', 'id2', 'id3'];
641
+ const substates = await Promise.all(
642
+ substateIds.map(id => provider.getSubstate({ substate_id: id }))
643
+ );
644
+ ```
645
+
646
+ ### Caching
647
+
648
+ ```typescript
649
+ // Implement simple caching for template definitions
650
+ const templateCache = new Map<string, TemplateDefinition>();
651
+
652
+ async function getTemplateWithCache(address: string): Promise<TemplateDefinition> {
653
+ if (templateCache.has(address)) {
654
+ return templateCache.get(address)!;
655
+ }
656
+
657
+ const template = await provider.getTemplateDefinition(address);
658
+ templateCache.set(address, template);
659
+ return template;
660
+ }
661
+ ```
662
+
663
+ ---
664
+
665
+ *This API reference covers tari.js v1.0.0. For the latest updates, see our [GitHub repository](https://github.com/tari-project/tari.js).*