@mysten/docs 0.1.1

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