@mysten/sui 2.16.1 → 2.16.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/bcs/bcs.d.mts +6 -6
  3. package/dist/client/core-resolver.mjs +21 -12
  4. package/dist/client/core-resolver.mjs.map +1 -1
  5. package/dist/cryptography/signature.d.mts +6 -6
  6. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  7. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  8. package/dist/transactions/Transaction.d.mts +6 -6
  9. package/dist/version.mjs +1 -1
  10. package/dist/version.mjs.map +1 -1
  11. package/dist/zklogin/bcs.d.mts +14 -14
  12. package/dist/zklogin/bcs.d.mts.map +1 -1
  13. package/docs/bcs.md +134 -0
  14. package/docs/clients/core.md +622 -0
  15. package/docs/clients/graphql.md +101 -0
  16. package/docs/clients/grpc.md +210 -0
  17. package/docs/clients/index.md +95 -0
  18. package/docs/clients/json-rpc.md +239 -0
  19. package/docs/cryptography/keypairs.md +267 -0
  20. package/docs/cryptography/multisig.md +194 -0
  21. package/docs/cryptography/passkey.md +112 -0
  22. package/docs/cryptography/webcrypto-signer.md +81 -0
  23. package/docs/executors.md +150 -0
  24. package/docs/faucet.md +26 -0
  25. package/docs/hello-sui.md +115 -0
  26. package/docs/index.md +53 -0
  27. package/docs/install.md +61 -0
  28. package/docs/llm-docs.md +32 -0
  29. package/docs/llms-index.md +44 -0
  30. package/docs/migrations/0.38.md +58 -0
  31. package/docs/migrations/sui-1.0.md +455 -0
  32. package/docs/migrations/sui-2.0/agent-prompt.md +42 -0
  33. package/docs/migrations/sui-2.0/dapp-kit.md +350 -0
  34. package/docs/migrations/sui-2.0/deepbook-v3.md +33 -0
  35. package/docs/migrations/sui-2.0/index.md +158 -0
  36. package/docs/migrations/sui-2.0/json-rpc-migration.md +408 -0
  37. package/docs/migrations/sui-2.0/kiosk.md +120 -0
  38. package/docs/migrations/sui-2.0/sdk-maintainers.md +90 -0
  39. package/docs/migrations/sui-2.0/seal.md +14 -0
  40. package/docs/migrations/sui-2.0/sui.md +341 -0
  41. package/docs/migrations/sui-2.0/suins.md +44 -0
  42. package/docs/migrations/sui-2.0/wallet-builders.md +66 -0
  43. package/docs/migrations/sui-2.0/walrus.md +41 -0
  44. package/docs/migrations/sui-2.0/zksend.md +95 -0
  45. package/docs/plugins.md +258 -0
  46. package/docs/sdk-building.md +344 -0
  47. package/docs/transaction-building/basics.md +299 -0
  48. package/docs/transaction-building/gas.md +61 -0
  49. package/docs/transaction-building/intents.md +62 -0
  50. package/docs/transaction-building/offline.md +73 -0
  51. package/docs/transaction-building/sponsored-transactions.md +22 -0
  52. package/docs/utils/derived_objects.md +80 -0
  53. package/docs/utils/index.md +59 -0
  54. package/docs/zklogin.md +83 -0
  55. package/package.json +3 -3
  56. package/src/client/core-resolver.ts +48 -13
  57. package/src/version.ts +1 -1
@@ -0,0 +1,622 @@
1
+ # Core API
2
+
3
+ > Transport-agnostic Core API shared by all Sui clients.
4
+
5
+ The Core API is the transport-agnostic interface that all Sui clients implement. It provides a
6
+ consistent set of methods for interacting with the Sui blockchain, regardless of whether you're
7
+ using gRPC, GraphQL, or JSON-RPC.
8
+
9
+ ## `ClientWithCoreApi`
10
+
11
+ The `ClientWithCoreApi` type represents any client that implements the Core API. Use this type when
12
+ building SDKs or libraries that should work with any transport:
13
+
14
+ ```typescript
15
+
16
+ // Your SDK works with any client
17
+ class MySDK {
18
+ constructor(private client: ClientWithCoreApi) {}
19
+
20
+ async doSomething() {
21
+ // Use client.core for all operations
22
+ return this.client.core.getObject({ objectId: '0x...' });
23
+ }
24
+ }
25
+ ```
26
+
27
+ ## Object methods
28
+
29
+ Object methods accept an optional `include` parameter to control what data is returned. By default,
30
+ every object comes with `objectId`, `version`, `digest`, `owner`, and `type`. The following fields
31
+ are only populated when requested:
32
+
33
+ | Option | Type | Description |
34
+ | --------------------- | --------- | ------------------------------------------------------------------------- |
35
+ | `content` | `boolean` | BCS-encoded Move struct content (pass this to generated BCS type parsers) |
36
+ | `previousTransaction` | `boolean` | Digest of the transaction that last mutated this object |
37
+ | `json` | `boolean` | JSON representation of the object's Move struct content |
38
+ | `objectBcs` | `boolean` | Full BCS-encoded object envelope (rarely needed; see [below](#objectbcs)) |
39
+ | `display` | `boolean` | [Sui Display Standard](https://docs.sui.io/standards/display) metadata |
40
+
41
+ ### `getObject`
42
+
43
+ Fetch a single object by ID.
44
+
45
+ ```typescript
46
+ const { object } = await client.core.getObject({
47
+ objectId: '0x123...',
48
+ include: {
49
+ content: true, // Include BCS-encoded content
50
+ previousTransaction: true, // Include creating transaction digest
51
+ },
52
+ });
53
+
54
+ console.log(object.objectId);
55
+ console.log(object.version);
56
+ console.log(object.digest);
57
+ console.log(object.type); // e.g., "0x2::coin::Coin<0x2::sui::SUI>"
58
+ ```
59
+
60
+ ### `getObjects`
61
+
62
+ Fetch multiple objects in a single request.
63
+
64
+ ```typescript
65
+ const { objects } = await client.core.getObjects({
66
+ objectIds: ['0x123...', '0x456...'],
67
+ include: { content: true },
68
+ });
69
+
70
+ for (const obj of objects) {
71
+ if (obj instanceof Error) {
72
+ console.log('Object not found:', obj.message);
73
+ } else {
74
+ console.log(obj.objectId, obj.type);
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### `listOwnedObjects`
80
+
81
+ List objects owned by an address.
82
+
83
+ ```typescript
84
+ const result = await client.core.listOwnedObjects({
85
+ owner: '0xabc...',
86
+ filter: {
87
+ StructType: '0x2::coin::Coin<0x2::sui::SUI>',
88
+ },
89
+ limit: 10,
90
+ });
91
+
92
+ for (const obj of result.objects) {
93
+ console.log(obj.objectId, obj.type);
94
+ }
95
+
96
+ // Paginate
97
+ if (result.cursor) {
98
+ const nextPage = await client.core.listOwnedObjects({
99
+ owner: '0xabc...',
100
+ cursor: result.cursor,
101
+ });
102
+ }
103
+ ```
104
+
105
+ ### Parsing object content
106
+
107
+ Use `include: { content: true }` to get the BCS-encoded Move struct bytes, then parse them with
108
+ generated types (from `@mysten/codegen`) or manual BCS definitions:
109
+
110
+ ```typescript
111
+
112
+ const { object } = await client.core.getObject({
113
+ objectId: '0x123...',
114
+ include: { content: true },
115
+ });
116
+
117
+ const parsed = MyStruct.parse(object.content);
118
+ ```
119
+
120
+ ### `json` include option
121
+
122
+ You can also fetch a JSON representation of the object's content with `include: { json: true }`.
123
+
124
+ > **Warning:** The `json` field structure might vary between API implementations. For example, JSON-RPC returns
125
+ > UID fields as nested objects (`{ "id": { "id": "0x..." } }`), while gRPC and GraphQL flatten
126
+ > them (`{ "id": "0x..." }`). For consistent data across all clients, use `content` and parse BCS
127
+ > directly.
128
+
129
+ ### `objectBcs`
130
+
131
+ The `objectBcs` option returns the full BCS-encoded object envelope, which is the struct content
132
+ wrapped in metadata (type, `hasPublicTransfer`, version, owner, previous transaction, and storage
133
+ rebate). Most of this metadata is already available as fields on the object response, so you
134
+ typically only need `content`. If you do need `objectBcs`, parse it with `bcs.Object` from
135
+ `@mysten/sui/bcs`:
136
+
137
+ ```typescript
138
+
139
+ const envelope = bcs.Object.parse(object.objectBcs);
140
+ ```
141
+
142
+ > **Error:** Do not pass `objectBcs` to a Move struct parser. It contains wrapping metadata that will cause
143
+ > parsing to fail or produce incorrect results. Use `content` for parsing Move struct fields.
144
+
145
+ ### `display` include option
146
+
147
+ The `display` option fetches [Sui Display Standard](https://docs.sui.io/standards/display) metadata
148
+ for an object. Display templates define how an object should be presented in wallets and explorers,
149
+ including fields like `name`, `description`, and `image_url`.
150
+
151
+ ```typescript
152
+ const { object } = await client.core.getObject({
153
+ objectId: '0x123...',
154
+ include: { display: true },
155
+ });
156
+
157
+ if (object.display) {
158
+ // display is null if the object's type has no Display template
159
+ console.log(object.display.output?.name);
160
+ console.log(object.display.output?.image_url);
161
+ }
162
+ ```
163
+
164
+ The `display` field is `null` when the object's type has no registered Display template, and
165
+ `undefined` when `display` was not requested. The `Display` type has two fields:
166
+
167
+ | Field | Type | Description |
168
+ | -------- | -------------------------------- | --------------------------------------------------------------- |
169
+ | `output` | `Record<string, string> \| null` | Interpolated display fields (template variables resolved) |
170
+ | `errors` | `Record<string, string> \| null` | Per-field errors if any template variable failed to interpolate |
171
+
172
+ `display` works with `getObject`, `getObjects`, and `listOwnedObjects`.
173
+
174
+ ## Coin and balance methods
175
+
176
+ ### `getBalance`
177
+
178
+ Get the balance of a specific coin type for an owner.
179
+
180
+ ```typescript
181
+ const balance = await client.core.getBalance({
182
+ owner: '0xabc...',
183
+ coinType: '0x2::sui::SUI', // Optional, defaults to SUI
184
+ });
185
+
186
+ console.log(balance.totalBalance); // Total balance as bigint
187
+ console.log(balance.coinObjectCount); // Number of coin objects
188
+ ```
189
+
190
+ ### `listBalances`
191
+
192
+ List all coin balances for an owner.
193
+
194
+ ```typescript
195
+ const { balances } = await client.core.listBalances({
196
+ owner: '0xabc...',
197
+ });
198
+
199
+ for (const balance of balances) {
200
+ console.log(balance.coinType, balance.totalBalance);
201
+ }
202
+ ```
203
+
204
+ ### `listCoins`
205
+
206
+ List coin objects of a specific type owned by an address.
207
+
208
+ ```typescript
209
+ const result = await client.core.listCoins({
210
+ owner: '0xabc...',
211
+ coinType: '0x2::sui::SUI',
212
+ limit: 10,
213
+ });
214
+
215
+ for (const coin of result.coins) {
216
+ console.log(coin.objectId, coin.balance);
217
+ }
218
+ ```
219
+
220
+ ### `getCoinMetadata`
221
+
222
+ Get metadata for a coin type, including its name, symbol, decimals, and description.
223
+
224
+ ```typescript
225
+ const { coinMetadata } = await client.core.getCoinMetadata({
226
+ coinType: '0x2::sui::SUI',
227
+ });
228
+
229
+ if (coinMetadata) {
230
+ console.log(coinMetadata.name, coinMetadata.symbol, coinMetadata.decimals);
231
+ // "Sui" "SUI" 9
232
+ }
233
+ ```
234
+
235
+ ## Dynamic field methods
236
+
237
+ ### `listDynamicFields`
238
+
239
+ List dynamic fields on an object.
240
+
241
+ ```typescript
242
+ const result = await client.core.listDynamicFields({
243
+ parentId: '0x123...',
244
+ limit: 10,
245
+ });
246
+
247
+ for (const field of result.dynamicFields) {
248
+ console.log(field.name, field.type);
249
+ }
250
+ ```
251
+
252
+ ### `getDynamicField`
253
+
254
+ Get a specific dynamic field by name.
255
+
256
+ ```typescript
257
+
258
+ const { dynamicField } = await client.core.getDynamicField({
259
+ parentId: '0x123...',
260
+ name: {
261
+ type: 'u64',
262
+ bcs: bcs.u64().serialize(42).toBytes(),
263
+ },
264
+ });
265
+
266
+ console.log(dynamicField.name);
267
+ console.log(dynamicField.value.type);
268
+ console.log(dynamicField.value.bcs); // BCS-encoded value
269
+ ```
270
+
271
+ ### `getDynamicObjectField`
272
+
273
+ Get a dynamic object field, returning the referenced object. Supports the same
274
+ [object include options](#object-methods) as `getObject`.
275
+
276
+ ```typescript
277
+ const { object } = await client.core.getDynamicObjectField({
278
+ parentId: '0x123...',
279
+ name: {
280
+ type: '0x2::object::ID',
281
+ bcs: bcs.Address.serialize('0x456...').toBytes(),
282
+ },
283
+ include: { content: true },
284
+ });
285
+ ```
286
+
287
+ ## Transaction methods
288
+
289
+ Transaction methods accept an optional `include` parameter to control what data is returned. By
290
+ default, every transaction result includes `digest`, `signatures`, `epoch`, and `status`. The
291
+ following fields are only populated when requested:
292
+
293
+ | Option | Type | Description |
294
+ | ---------------- | --------- | ------------------------------------------------------------------ |
295
+ | `effects` | `boolean` | Parsed transaction effects (gas used, changed objects, and status) |
296
+ | `events` | `boolean` | Events emitted during execution |
297
+ | `transaction` | `boolean` | Parsed transaction data (sender, gas config, inputs, commands) |
298
+ | `balanceChanges` | `boolean` | Balance changes caused by the transaction |
299
+ | `objectTypes` | `boolean` | Map of object IDs to their types for all changed objects |
300
+ | `bcs` | `boolean` | Raw BCS-encoded transaction bytes |
301
+
302
+ `simulateTransaction` also supports:
303
+
304
+ | Option | Type | Description |
305
+ | ---------------- | --------- | ------------------------------------------------------ |
306
+ | `commandResults` | `boolean` | Return values and mutated references from each command |
307
+
308
+ ### `executeTransaction`
309
+
310
+ Execute a signed transaction.
311
+
312
+ ```typescript
313
+ const result = await client.core.executeTransaction({
314
+ transaction: transactionBytes,
315
+ signatures: [signature],
316
+ include: {
317
+ effects: true,
318
+ events: true,
319
+ },
320
+ });
321
+
322
+ if (result.Transaction) {
323
+ console.log('Success:', result.Transaction.digest);
324
+ console.log('Effects:', result.Transaction.effects);
325
+ } else {
326
+ console.log('Failed:', result.FailedTransaction?.status.error);
327
+ }
328
+ ```
329
+
330
+ ### `simulateTransaction`
331
+
332
+ Simulate a transaction without executing it.
333
+
334
+ ```typescript
335
+ const result = await client.core.simulateTransaction({
336
+ transaction: transactionBytes,
337
+ include: {
338
+ effects: true,
339
+ balanceChanges: true,
340
+ commandResults: true, // simulation-only option
341
+ },
342
+ });
343
+
344
+ // Check simulated effects before signing
345
+ console.log(result.effects);
346
+ console.log(result.balanceChanges);
347
+ ```
348
+
349
+ #### Disabling checks
350
+
351
+ By default, `simulateTransaction` runs with full transaction validation. For example when inspecting
352
+ non-public or non-entry Move functions set `checksEnabled: false`:
353
+
354
+ ```typescript
355
+ const result = await client.core.simulateTransaction({
356
+ transaction: transactionBytes,
357
+ checksEnabled: false,
358
+ include: {
359
+ commandResults: true,
360
+ },
361
+ });
362
+ ```
363
+
364
+ ### `signAndExecuteTransaction`
365
+
366
+ Sign and execute a transaction in one step.
367
+
368
+ ```typescript
369
+
370
+ const tx = new Transaction();
371
+ tx.transferObjects([tx.object('0x123...')], '0xrecipient...');
372
+
373
+ const result = await client.core.signAndExecuteTransaction({
374
+ transaction: tx,
375
+ signer: keypair,
376
+ include: { effects: true },
377
+ });
378
+
379
+ // Always check the result
380
+ if (result.FailedTransaction) {
381
+ throw new Error(`Failed: ${result.FailedTransaction.status.error}`);
382
+ }
383
+
384
+ console.log('Digest:', result.Transaction.digest);
385
+ ```
386
+
387
+ ### `getTransaction`
388
+
389
+ Fetch a transaction by digest.
390
+
391
+ ```typescript
392
+ const result = await client.core.getTransaction({
393
+ digest: 'ABC123...',
394
+ include: {
395
+ effects: true,
396
+ events: true,
397
+ transaction: true,
398
+ },
399
+ });
400
+
401
+ console.log(result.Transaction?.digest);
402
+ console.log(result.Transaction?.effects);
403
+ console.log(result.Transaction?.transaction?.sender);
404
+ ```
405
+
406
+ You can also fetch raw BCS-encoded transaction bytes:
407
+
408
+ ```typescript
409
+ const result = await client.core.getTransaction({
410
+ digest: 'ABC123...',
411
+ include: { bcs: true },
412
+ });
413
+
414
+ // Raw BCS bytes for the transaction
415
+ console.log(result.Transaction?.bcs); // Uint8Array
416
+ ```
417
+
418
+ ### `waitForTransaction`
419
+
420
+ Wait for a transaction to be available.
421
+
422
+ ```typescript
423
+ const result = await client.core.waitForTransaction({
424
+ digest: 'ABC123...',
425
+ timeout: 60_000, // 60 seconds
426
+ include: { effects: true },
427
+ });
428
+ ```
429
+
430
+ You can also pass the result directly from `executeTransaction`:
431
+
432
+ ```typescript
433
+ const executeResult = await client.core.executeTransaction({ ... });
434
+
435
+ const finalResult = await client.core.waitForTransaction({
436
+ result: executeResult,
437
+ include: { effects: true },
438
+ });
439
+ ```
440
+
441
+ ## System methods
442
+
443
+ ### `getReferenceGasPrice`
444
+
445
+ Get the current reference gas price.
446
+
447
+ ```typescript
448
+ const { referenceGasPrice } = await client.core.getReferenceGasPrice();
449
+ console.log(referenceGasPrice); // bigint
450
+ ```
451
+
452
+ ### `getCurrentSystemState`
453
+
454
+ Get the current system state including epoch information.
455
+
456
+ ```typescript
457
+ const systemState = await client.core.getCurrentSystemState();
458
+ console.log(systemState.epoch);
459
+ console.log(systemState.systemStateVersion);
460
+ ```
461
+
462
+ ### `getChainIdentifier`
463
+
464
+ Get the chain identifier for the network.
465
+
466
+ ```typescript
467
+ const { chainIdentifier } = await client.core.getChainIdentifier();
468
+ console.log(chainIdentifier); // e.g., "4c78adac"
469
+ ```
470
+
471
+ ## Move methods
472
+
473
+ ### `getMoveFunction`
474
+
475
+ Get information about a Move function.
476
+
477
+ ```typescript
478
+ const { function: fn } = await client.core.getMoveFunction({
479
+ packageId: '0x2',
480
+ moduleName: 'coin',
481
+ name: 'transfer',
482
+ });
483
+
484
+ console.log(fn.name);
485
+ console.log(fn.parameters);
486
+ console.log(fn.typeParameters);
487
+ ```
488
+
489
+ ## Name service methods
490
+
491
+ ### `defaultNameServiceName`
492
+
493
+ Resolve an address to its default SuiNS name.
494
+
495
+ ```typescript
496
+ const { name } = await client.core.defaultNameServiceName({
497
+ address: '0xabc...',
498
+ });
499
+
500
+ console.log(name); // e.g., "example.sui"
501
+ ```
502
+
503
+ ## MVR methods
504
+
505
+ The client also exposes MVR (Move Registry) methods through `client.core.mvr`:
506
+
507
+ ### `resolveType`
508
+
509
+ Resolve a type name (including `.move` names) to a fully qualified type.
510
+
511
+ ```typescript
512
+ const { type } = await client.core.mvr.resolveType({
513
+ type: '@mysten/sui::coin::Coin<@mysten/sui::sui::SUI>',
514
+ });
515
+
516
+ console.log(type); // "0x2::coin::Coin<0x2::sui::SUI>"
517
+ ```
518
+
519
+ ## Error handling
520
+
521
+ Methods that fetch objects might return errors in the result:
522
+
523
+ ```typescript
524
+ const { objects } = await client.core.getObjects({
525
+ objectIds: ['0x123...', '0x456...'],
526
+ });
527
+
528
+ for (const obj of objects) {
529
+ if (obj instanceof Error) {
530
+ // Object not found or other error
531
+ console.error('Error:', obj.message);
532
+ } else {
533
+ // Successfully fetched
534
+ console.log(obj.objectId);
535
+ }
536
+ }
537
+ ```
538
+
539
+ For transaction execution, always check the result type:
540
+
541
+ ```typescript
542
+ const result = await client.core.executeTransaction({ ... });
543
+
544
+ if (result.Transaction) {
545
+ // Success
546
+ console.log(result.Transaction.digest);
547
+ } else if (result.FailedTransaction) {
548
+ // Transaction was executed but failed
549
+ throw new Error(result.FailedTransaction.status.error);
550
+ }
551
+ ```
552
+
553
+ ## `SuiClientTypes` Namespace
554
+
555
+ The `SuiClientTypes` namespace contains all type definitions for the Core API. Import it when you
556
+ need to type function parameters, return values, or variables:
557
+
558
+ ```typescript
559
+
560
+ // Type function parameters
561
+ function processObject(obj: SuiClientTypes.Object<{ content: true }>) {
562
+ console.log(obj.objectId, obj.content);
563
+ }
564
+
565
+ // Type return values
566
+ async function fetchBalance(
567
+ client: ClientWithCoreApi,
568
+ owner: string,
569
+ ): Promise<SuiClientTypes.CoinBalance> {
570
+ const { balance } = await client.core.getBalance({ owner });
571
+ return balance;
572
+ }
573
+
574
+ // Type options
575
+ const options: SuiClientTypes.GetObjectOptions<{ content: true }> = {
576
+ objectId: '0x123...',
577
+ include: { content: true },
578
+ };
579
+ ```
580
+
581
+ ### Common types
582
+
583
+ | Type | Description |
584
+ | ---------------------- | ------------------------------------------- |
585
+ | `Object<Include>` | Fetched object with optional included data |
586
+ | `Coin` | Coin object with balance |
587
+ | `CoinBalance` | Balance summary for a coin type |
588
+ | `CoinMetadata` | Metadata for a coin type |
589
+ | `Transaction<Include>` | Executed transaction with optional data |
590
+ | `TransactionResult` | Success or failure result from execution |
591
+ | `TransactionEffects` | Detailed effects from transaction execution |
592
+ | `Event` | Emitted event from a transaction |
593
+ | `ObjectOwner` | Union of all owner types |
594
+ | `ExecutionStatus` | Success/failure status with error details |
595
+ | `DynamicFieldName` | Name identifier for dynamic fields |
596
+ | `FunctionResponse` | Move function metadata |
597
+ | `Network` | Network identifier type |
598
+
599
+ ### Include options types
600
+
601
+ | Type | Description |
602
+ | ---------------------------- | --------------------------------------- |
603
+ | `ObjectInclude` | Options for object data inclusion |
604
+ | `TransactionInclude` | Options for transaction data inclusion |
605
+ | `SimulateTransactionInclude` | Extended options for simulation results |
606
+
607
+ ### Method options types
608
+
609
+ | Type | Description |
610
+ | ---------------------------------- | --------------------------------------- |
611
+ | `GetObjectOptions` | Options for `getObject` |
612
+ | `GetObjectsOptions` | Options for `getObjects` |
613
+ | `ListOwnedObjectsOptions` | Options for `listOwnedObjects` |
614
+ | `ListCoinsOptions` | Options for `listCoins` |
615
+ | `GetBalanceOptions` | Options for `getBalance` |
616
+ | `ListBalancesOptions` | Options for `listBalances` |
617
+ | `GetCoinMetadataOptions` | Options for `getCoinMetadata` |
618
+ | `ExecuteTransactionOptions` | Options for `executeTransaction` |
619
+ | `SimulateTransactionOptions` | Options for `simulateTransaction` |
620
+ | `SignAndExecuteTransactionOptions` | Options for `signAndExecuteTransaction` |
621
+ | `GetTransactionOptions` | Options for `getTransaction` |
622
+ | `WaitForTransactionOptions` | Options for `waitForTransaction` |
@@ -0,0 +1,101 @@
1
+ # SuiGraphQLClient
2
+
3
+ > Connect to Sui through GraphQL with SuiGraphQLClient.
4
+
5
+ The `SuiGraphQLClient` enables type-safe GraphQL queries against the Sui GraphQL API.
6
+
7
+ For more details on the Sui GraphQL API, see the
8
+ [GraphQL reference](https://docs.sui.io/references/sui-graphql).
9
+
10
+ The `SuiGraphQLClient` implements all the the [Core API](/sui/clients/core) methods:
11
+
12
+ ```typescript
13
+
14
+ const client = new SuiGraphQLClient({
15
+ url: 'https://sui-mainnet.mystenlabs.com/graphql',
16
+ network: 'mainnet',
17
+ });
18
+
19
+ const { object } = await client.getObject({ objectId: '0x...' });
20
+ ```
21
+
22
+ ## Custom GraphQL queries
23
+
24
+ To query anything no in the Core API, you can use the `query` method to execute custom GraphQL
25
+ queries.
26
+
27
+ We'll start by creating our client, and executing a very basic query:
28
+
29
+ ```typescript
30
+
31
+ const gqlClient = new SuiGraphQLClient({
32
+ url: 'https://graphql.testnet.sui.io/graphql',
33
+ network: 'testnet',
34
+ });
35
+
36
+ const chainIdentifierQuery = graphql(`
37
+ query {
38
+ chainIdentifier
39
+ }
40
+ `);
41
+
42
+ async function getChainIdentifier() {
43
+ const result = await gqlClient.query({
44
+ query: chainIdentifierQuery,
45
+ });
46
+
47
+ return result.data?.chainIdentifier;
48
+ }
49
+ ```
50
+
51
+ ## Type-safety for GraphQL queries
52
+
53
+ You might have noticed the example above does not include any type definitions for the query. The
54
+ `graphql` function used in the example is powered by [`gql.tada`](https://gql-tada.0no.co/) and will
55
+ automatically provide the required type information to ensure that your queries are properly typed
56
+ when executed through `SuiGraphQLClient`.
57
+
58
+ The `graphql` function detects variables used by your query, and will ensure that the variables
59
+ passed to your query are properly typed.
60
+
61
+ ```typescript
62
+ const getSuinsName = graphql(`
63
+ query getSuiName($address: SuiAddress!) {
64
+ address(address: $address) {
65
+ defaultSuinsName
66
+ }
67
+ }
68
+ `);
69
+
70
+ async function getDefaultSuinsName(address: string) {
71
+ const result = await gqlClient.query({
72
+ query: getSuinsName,
73
+ variables: {
74
+ address,
75
+ },
76
+ });
77
+
78
+ return result.data?.address?.defaultSuinsName;
79
+ }
80
+ ```
81
+
82
+ ## Using typed GraphQL queries with other GraphQL clients
83
+
84
+ The `graphql` function returns document nodes that implement the
85
+ [`TypedDocumentNode`](https://github.com/dotansimha/graphql-typed-document-node) standard, and will
86
+ work with the majority of popular GraphQL clients to provide queries that are automatically typed.
87
+
88
+ ```typescript
89
+
90
+ const chainIdentifierQuery = graphql(`
91
+ query {
92
+ chainIdentifier
93
+ }
94
+ `);
95
+
96
+ function ChainIdentifier() {
97
+ const { loading, error, data } = useQuery(getPokemonsQuery);
98
+
99
+ return <div>{data?.chainIdentifier}</div>;
100
+ }
101
+ ```