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