@mysten/sui 2.23.2 → 2.24.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 (73) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +9 -9
  3. package/dist/bcs/index.d.mts +36 -36
  4. package/dist/client/core.d.mts +1 -0
  5. package/dist/client/core.d.mts.map +1 -1
  6. package/dist/client/core.mjs.map +1 -1
  7. package/dist/client/types.d.mts +7 -0
  8. package/dist/client/types.d.mts.map +1 -1
  9. package/dist/graphql/client.d.mts +1 -0
  10. package/dist/graphql/client.d.mts.map +1 -1
  11. package/dist/graphql/client.mjs +3 -0
  12. package/dist/graphql/client.mjs.map +1 -1
  13. package/dist/graphql/core.d.mts +1 -0
  14. package/dist/graphql/core.d.mts.map +1 -1
  15. package/dist/graphql/core.mjs +10 -1
  16. package/dist/graphql/core.mjs.map +1 -1
  17. package/dist/graphql/generated/queries.d.mts.map +1 -1
  18. package/dist/graphql/generated/queries.mjs +8 -1
  19. package/dist/graphql/generated/queries.mjs.map +1 -1
  20. package/dist/grpc/client.d.mts +1 -0
  21. package/dist/grpc/client.d.mts.map +1 -1
  22. package/dist/grpc/client.mjs +3 -0
  23. package/dist/grpc/client.mjs.map +1 -1
  24. package/dist/grpc/core.d.mts +1 -0
  25. package/dist/grpc/core.d.mts.map +1 -1
  26. package/dist/grpc/core.mjs +20 -0
  27. package/dist/grpc/core.mjs.map +1 -1
  28. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  29. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  30. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  31. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  32. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  33. package/dist/jsonRpc/core.d.mts +5 -0
  34. package/dist/jsonRpc/core.d.mts.map +1 -1
  35. package/dist/jsonRpc/core.mjs +7 -0
  36. package/dist/jsonRpc/core.mjs.map +1 -1
  37. package/dist/transactions/Transaction.d.mts +3 -3
  38. package/dist/transactions/data/v1.d.mts +220 -220
  39. package/dist/transactions/data/v1.d.mts.map +1 -1
  40. package/dist/transactions/data/v2.d.mts +16 -16
  41. package/dist/transactions/data/v2.d.mts.map +1 -1
  42. package/dist/version.mjs +1 -1
  43. package/dist/version.mjs.map +1 -1
  44. package/docs/clients/core.md +31 -10
  45. package/docs/clients/graphql.md +43 -8
  46. package/docs/clients/grpc.md +91 -9
  47. package/docs/clients/index.md +86 -39
  48. package/docs/clients/json-rpc.md +30 -26
  49. package/docs/executors.md +28 -13
  50. package/docs/index.md +1 -1
  51. package/docs/llms-index.md +17 -17
  52. package/docs/migrations/sui-2.0/dapp-kit.md +3 -3
  53. package/docs/migrations/sui-2.0/deepbook-v3.md +2 -2
  54. package/docs/migrations/sui-2.0/index.md +46 -25
  55. package/docs/migrations/sui-2.0/json-rpc-migration.md +460 -284
  56. package/docs/migrations/sui-2.0/kiosk.md +10 -9
  57. package/docs/migrations/sui-2.0/sdk-maintainers.md +17 -11
  58. package/docs/migrations/sui-2.0/sui.md +47 -29
  59. package/docs/migrations/sui-2.0/suins.md +2 -2
  60. package/docs/migrations/sui-2.0/walrus.md +3 -3
  61. package/docs/migrations/sui-2.0/zksend.md +9 -8
  62. package/docs/sdk-building.md +7 -5
  63. package/package.json +1 -1
  64. package/src/client/core.ts +4 -0
  65. package/src/client/types.ts +11 -0
  66. package/src/graphql/client.ts +6 -0
  67. package/src/graphql/core.ts +15 -0
  68. package/src/graphql/generated/queries.ts +14 -0
  69. package/src/graphql/queries/nameService.graphql +6 -0
  70. package/src/grpc/client.ts +6 -0
  71. package/src/grpc/core.ts +35 -0
  72. package/src/jsonRpc/core.ts +12 -0
  73. package/src/version.ts +1 -1
@@ -1,10 +1,15 @@
1
1
  # Core API
2
2
 
3
- > Transport-agnostic Core API shared by all Sui clients.
3
+ > Transport-agnostic Core API shared by Sui clients
4
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.
5
+ The Core API is the transport-agnostic interface shared by Sui clients. It provides a consistent set
6
+ of methods for interacting with the Sui blockchain across `SuiGrpcClient`, `SuiGraphQLClient`, and
7
+ the deprecated `SuiJsonRpcClient`.
8
+
9
+ For application code, prefer the top-level methods on the concrete client you instantiate, such as
10
+ `grpcClient.getObject()` or `graphqlClient.listTransactions()`. Those methods match the Core API for
11
+ common operations and may expose transport-specific additions. Use `client.core` when writing SDKs,
12
+ libraries, or helpers that accept any `ClientWithCoreApi`.
8
13
 
9
14
  ## `ClientWithCoreApi`
10
15
 
@@ -83,9 +88,7 @@ List objects owned by an address.
83
88
  ```typescript
84
89
  const result = await client.core.listOwnedObjects({
85
90
  owner: '0xabc...',
86
- filter: {
87
- StructType: '0x2::coin::Coin<0x2::sui::SUI>',
88
- },
91
+ type: '0x2::coin::Coin<0x2::sui::SUI>',
89
92
  limit: 10,
90
93
  });
91
94
 
@@ -342,9 +345,12 @@ const result = await client.core.simulateTransaction({
342
345
  },
343
346
  });
344
347
 
348
+ const simulatedTransaction =
349
+ result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;
350
+
345
351
  // Check simulated effects before signing
346
- console.log(result.effects);
347
- console.log(result.balanceChanges);
352
+ console.log(simulatedTransaction.effects);
353
+ console.log(simulatedTransaction.balanceChanges);
348
354
  ```
349
355
 
350
356
  #### Disabling checks
@@ -598,12 +604,27 @@ console.log(fn.typeParameters);
598
604
 
599
605
  ## Name service methods
600
606
 
607
+ ### `resolveNameServiceAddress`
608
+
609
+ Resolve a SuiNS name to its target address. The address is `null` when the name does not exist, has
610
+ expired, or does not have a target address.
611
+
612
+ ```typescript
613
+ const { address } = await client.core.resolveNameServiceAddress({
614
+ name: 'example.sui',
615
+ });
616
+
617
+ console.log(address); // e.g., "0x..." or null
618
+ ```
619
+
601
620
  ### `defaultNameServiceName`
602
621
 
603
622
  Resolve an address to its default SuiNS name.
604
623
 
605
624
  ```typescript
606
- const { name } = await client.core.defaultNameServiceName({
625
+ const {
626
+ data: { name },
627
+ } = await client.core.defaultNameServiceName({
607
628
  address: '0xabc...',
608
629
  });
609
630
 
@@ -1,27 +1,60 @@
1
1
  # SuiGraphQLClient
2
2
 
3
- > Connect to Sui through GraphQL with SuiGraphQLClient.
3
+ > Connect to Sui through GraphQL with SuiGraphQLClient
4
4
 
5
5
  The `SuiGraphQLClient` enables type-safe GraphQL queries against the Sui GraphQL API.
6
6
 
7
7
  For more details on the Sui GraphQL API, see the
8
8
  [GraphQL reference](https://docs.sui.io/references/sui-graphql).
9
9
 
10
- The `SuiGraphQLClient` implements all the the [Core API](/sui/clients/core) methods:
10
+ Use `SuiGraphQLClient` when an app needs indexed GraphQL data, historical queries, or custom
11
+ selection sets that are not exposed by the gRPC top-level API.
12
+
13
+ ## Using top-level methods
14
+
15
+ `SuiGraphQLClient` exposes top-level methods for the same common operations as the
16
+ [Core API](/sui/clients/core). Use them directly in application code:
11
17
 
12
18
  ```typescript
13
19
 
14
20
  const client = new SuiGraphQLClient({
15
- url: 'https://sui-mainnet.mystenlabs.com/graphql',
21
+ url: 'https://graphql.mainnet.sui.io/graphql',
16
22
  network: 'mainnet',
17
23
  });
18
24
 
19
- const { object } = await client.getObject({ objectId: '0x...' });
25
+ const { object } = await client.getObject({
26
+ objectId: '0x...',
27
+ include: { content: true },
28
+ });
29
+
30
+ const txs = await client.listTransactions({
31
+ filter: { sender: '0x...' },
32
+ order: 'descending',
33
+ limit: 10,
34
+ });
20
35
  ```
21
36
 
37
+ The same methods are available through `client.core` when SDK code needs the transport-agnostic
38
+ `ClientWithCoreApi` contract.
39
+
40
+ Common top-level methods:
41
+
42
+ | Category | Methods |
43
+ | -------------- | ----------------------------------------------------------------------------------------------------------------- |
44
+ | Objects | `getObject`, `getObjects`, `listOwnedObjects`, `listDynamicFields`, `getDynamicField` |
45
+ | Coins | `listCoins`, `getBalance`, `listBalances`, `getCoinMetadata` |
46
+ | Transactions | `getTransaction`, `executeTransaction`, `signAndExecuteTransaction`, `waitForTransaction` |
47
+ | Simulation | `simulateTransaction` |
48
+ | Queries | `listTransactions`, `listEvents` |
49
+ | Move and names | `getMoveFunction`, `resolveNameServiceAddress`, `defaultNameServiceName`, `mvr.resolvePackage`, `mvr.resolveType` |
50
+ | Verification | `verifyZkLoginSignature` |
51
+
52
+ GraphQL-specific top-level options include `doGasSelection` on `simulateTransaction` and
53
+ `include: { value: true }` on `listDynamicFields`.
54
+
22
55
  ## Custom GraphQL queries
23
56
 
24
- To query anything no in the Core API, you can use the `query` method to execute custom GraphQL
57
+ To query anything not in the top-level API, use the `query` method to execute custom GraphQL
25
58
  queries.
26
59
 
27
60
  We'll start by creating our client, and executing a very basic query:
@@ -62,7 +95,9 @@ passed to your query are properly typed.
62
95
  const getSuinsName = graphql(`
63
96
  query getSuiName($address: SuiAddress!) {
64
97
  address(address: $address) {
65
- defaultSuinsName
98
+ defaultNameRecord {
99
+ domain
100
+ }
66
101
  }
67
102
  }
68
103
  `);
@@ -75,7 +110,7 @@ async function getDefaultSuinsName(address: string) {
75
110
  },
76
111
  });
77
112
 
78
- return result.data?.address?.defaultSuinsName;
113
+ return result.data?.address?.defaultNameRecord?.domain;
79
114
  }
80
115
  ```
81
116
 
@@ -94,7 +129,7 @@ const chainIdentifierQuery = graphql(`
94
129
  `);
95
130
 
96
131
  function ChainIdentifier() {
97
- const { loading, error, data } = useQuery(getPokemonsQuery);
132
+ const { loading, error, data } = useQuery(chainIdentifierQuery);
98
133
 
99
134
  return <div>{data?.chainIdentifier}</div>;
100
135
  }
@@ -1,8 +1,9 @@
1
1
  # SuiGrpcClient
2
2
 
3
- > Connect to Sui through gRPC with SuiGrpcClient.
3
+ > Connect to Sui through gRPC with the recommended SuiGrpcClient
4
4
 
5
- The `SuiGrpcClient` provides access to the Full Node gRPC API.
5
+ The `SuiGrpcClient` provides access to the Full Node gRPC API. It is the recommended default client
6
+ for application code and SDK integrations.
6
7
 
7
8
  For more complete details on what is available through this API see the
8
9
  [gRPC API docs](https://docs.sui.io/develop/accessing-data/grpc/what-is-grpc).
@@ -28,6 +29,74 @@ const grpcClient = new SuiGrpcClient({
28
29
  });
29
30
  ```
30
31
 
32
+ ## Using top-level methods
33
+
34
+ Use top-level methods for most application code. These methods match the shared
35
+ [Core API](/sui/clients/core) option and response shapes, so the same calls can also be written as
36
+ `grpcClient.core.<method>()` when SDK code needs the transport-agnostic `ClientWithCoreApi`
37
+ contract.
38
+
39
+ ```typescript
40
+
41
+ const grpcClient = new SuiGrpcClient({
42
+ network: 'testnet',
43
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
44
+ });
45
+
46
+ const { balance } = await grpcClient.getBalance({
47
+ owner: '<OWNER_ADDRESS>',
48
+ });
49
+
50
+ const { object } = await grpcClient.getObject({
51
+ objectId: '<OBJECT_ID>',
52
+ include: { content: true, display: true },
53
+ });
54
+
55
+ const coins = await grpcClient.listCoins({
56
+ owner: '<OWNER_ADDRESS>',
57
+ coinType: '0x2::sui::SUI',
58
+ });
59
+ ```
60
+
61
+ Common top-level methods:
62
+
63
+ | Category | Methods |
64
+ | -------------- | ----------------------------------------------------------------------------------------------------------------- |
65
+ | Objects | `getObject`, `getObjects`, `listOwnedObjects`, `listDynamicFields`, `getDynamicField` |
66
+ | Coins | `listCoins`, `getBalance`, `listBalances`, `getCoinMetadata` |
67
+ | Transactions | `getTransaction`, `executeTransaction`, `signAndExecuteTransaction`, `waitForTransaction` |
68
+ | Simulation | `simulateTransaction` |
69
+ | Queries | `listTransactions`, `listEvents` |
70
+ | Move and names | `getMoveFunction`, `resolveNameServiceAddress`, `defaultNameServiceName`, `mvr.resolvePackage`, `mvr.resolveType` |
71
+ | Verification | `verifyZkLoginSignature` |
72
+
73
+ ### gRPC-specific top-level data
74
+
75
+ Top-level gRPC methods are a superset of the shared Core API where the transport can expose useful
76
+ gRPC data directly:
77
+
78
+ ```typescript
79
+ const result = await grpcClient.getTransaction({
80
+ digest: '<TRANSACTION_DIGEST>',
81
+ include: {
82
+ effects: true,
83
+ protoJson: true,
84
+ },
85
+ });
86
+
87
+ const tx = result.Transaction ?? result.FailedTransaction;
88
+ console.log(tx.digest, result.protoJson);
89
+ ```
90
+
91
+ gRPC-specific options include:
92
+
93
+ | Option | Methods |
94
+ | -------------------------- | ----------------------------------------------------------------------------------------- |
95
+ | `include.protoJson` | `getTransaction`, `executeTransaction`, `signAndExecuteTransaction`, `waitForTransaction` |
96
+ | `include.protoJson` | `simulateTransaction` |
97
+ | `doGasSelection` | `simulateTransaction` |
98
+ | `include: { value: true }` | `listDynamicFields` |
99
+
31
100
  ## Transport options
32
101
 
33
102
  By default, `SuiGrpcClient` uses `GrpcWebFetchTransport` from
@@ -105,9 +174,9 @@ service clients are generated using [protobuf-ts](https://github.com/timostamm/p
105
174
  provides type-safe gRPC clients for TypeScript. For more details on how to use gRPC with Sui, see
106
175
  the [gRPC overview](https://docs.sui.io/develop/accessing-data/grpc/what-is-grpc).
107
176
 
108
- ### With the core API
177
+ ### Prefer top-level methods first
109
178
 
110
- The gRPC client implements all the [`core`](./core) API methods:
179
+ For common operations, call the top-level method before reaching for raw service clients:
111
180
 
112
181
  ```typescript
113
182
 
@@ -115,13 +184,14 @@ const grpcClient = new SuiGrpcClient({
115
184
  network: 'testnet',
116
185
  baseUrl: 'https://fullnode.testnet.sui.io:443',
117
186
  });
118
- // Get coins owned by an address
119
- await grpcClient.getCoins({
187
+
188
+ await grpcClient.listCoins({
120
189
  owner: '<OWNER_ADDRESS>',
121
190
  });
122
191
  ```
123
192
 
124
- To query additional data not available in the core API, you can use the service clients directly:
193
+ Use the generated service clients directly when you need gRPC methods, read masks, streaming
194
+ behavior, or filters that are not exposed by the top-level API.
125
195
 
126
196
  ### Transaction execution service
127
197
 
@@ -254,8 +324,20 @@ const { response } = await grpcClient.movePackageService.getFunction({
254
324
  ### Name service
255
325
 
256
326
  ```typescript
257
- // Reverse lookup address to get name
258
- const { response } = await grpcClient.nameService.reverseLookupName({
327
+ const { address } = await grpcClient.resolveNameServiceAddress({
328
+ name: 'example.sui',
329
+ });
330
+ ```
331
+
332
+ Use the raw name service when you need the complete gRPC `NameRecord` instead of only its target
333
+ address:
334
+
335
+ ```typescript
336
+ const { response } = await grpcClient.nameService.lookupName({
337
+ name: 'example.sui',
338
+ });
339
+
340
+ const { response: reverseResponse } = await grpcClient.nameService.reverseLookupName({
259
341
  address: '0xabc...',
260
342
  });
261
343
  ```
@@ -1,28 +1,33 @@
1
1
  # Sui Clients
2
2
 
3
- > Choose and configure gRPC, GraphQL, or JSON-RPC clients for the Sui network.
3
+ > Choose and configure SuiGrpcClient, SuiGraphQLClient, and legacy JSON-RPC clients
4
4
 
5
5
  The Sui TypeScript SDK provides multiple client implementations for interacting with the Sui
6
- network. Each client connects to a different API but provides two levels of access:
6
+ network. For application code, choose one client for your transport and use its top-level methods
7
+ for common reads, writes, and queries. `SuiGrpcClient` is the recommended default.
7
8
 
8
- - Native API: Full access to everything the underlying API offers
9
- - [Core API](/sui/clients/core): A consistent interface across all clients for common operations
9
+ The gRPC and GraphQL clients expose three useful surfaces:
10
10
 
11
- ## Available clients
11
+ - Top-level methods: the main application API, matching the Core API for common operations
12
+ - [Core API](/sui/clients/core): the shared `client.core` contract used by SDKs and libraries
13
+ - Native API: direct access to transport-specific features when the common methods are not enough
14
+
15
+ The deprecated `SuiJsonRpcClient` also exposes `client.core`, but its top-level methods retain their
16
+ legacy JSON-RPC names and response shapes.
12
17
 
13
- | Client | API |
14
- | -------------------------------------------------------- | ------------------------------------------------------------------ |
15
- | [`SuiGrpcClient`](/sui/clients/grpc) (recommended) | [Full Node gRPC](https://docs.sui.io/references/fullnode-protocol) |
16
- | [`SuiGraphQLClient`](/sui/clients/graphql) | [GraphQL](https://docs.sui.io/references/sui-graphql) |
17
- | [`SuiJsonRpcClient`](/sui/clients/json-rpc) (deprecated) | [JSON-RPC (deprecated)](https://docs.sui.io/sui-api-ref) |
18
+ ## Available clients
18
19
 
19
- All clients are compatible with Mysten SDKs like `@mysten/walrus`, `@mysten/seal` and
20
- `@mysten/suins`.
20
+ | Client | Use For |
21
+ | -------------------------------------------------------- | ----------------------------------------------------------------------- |
22
+ | [`SuiGrpcClient`](/sui/clients/grpc) (recommended) | Most application and SDK operations, full node data, execution, streams |
23
+ | [`SuiGraphQLClient`](/sui/clients/graphql) | Indexed queries, historical data, or custom GraphQL selection sets |
24
+ | [`SuiJsonRpcClient`](/sui/clients/json-rpc) (deprecated) | Maintaining legacy JSON-RPC code while migrating to gRPC or GraphQL |
21
25
 
22
- For most application gRPC is a good default. The JSON RPC API has been deprecated and will be
23
- decommissioned soon. The GraphQL can be used for more advanced query patterns that can not be
24
- supported directly on full nodes (for example, querying for transactions or events with various
25
- filters).
26
+ All active Mysten SDKs are designed to accept clients that implement the Core API. `SuiGrpcClient`
27
+ is the default choice for most apps because it uses the full node gRPC API and has the most complete
28
+ top-level SDK surface. Use `SuiGraphQLClient` when the code needs GraphQL-specific indexed queries
29
+ or a custom query shape. JSON-RPC APIs are deprecated in the Sui TypeScript SDK; migrate legacy
30
+ JSON-RPC code to gRPC or GraphQL.
26
31
 
27
32
  ## Quick start
28
33
 
@@ -33,25 +38,82 @@ const client = new SuiGrpcClient({
33
38
  baseUrl: 'https://fullnode.mainnet.sui.io:443',
34
39
  });
35
40
 
36
- // Use the native API for full access to transport-specific features
37
- const { response } = await client.ledgerService.getTransaction({ digest: '0x...' });
41
+ const { balance } = await client.getBalance({ owner: '0x...' });
42
+ const { object } = await client.getObject({
43
+ objectId: '0x...',
44
+ include: { content: true },
45
+ });
46
+ ```
38
47
 
39
- // Use the Core API for transport-agnostic operations
40
- const { object } = await client.core.getObject({ objectId: '0x...' });
48
+ ## Top-level, core, and native APIs
49
+
50
+ ### Top-level methods
51
+
52
+ Use top-level methods when writing app code against `SuiGrpcClient` or `SuiGraphQLClient`. These
53
+ methods use the same option and response shapes as the Core API, and a transport can add narrowly
54
+ scoped fields where it has extra native data. For `SuiJsonRpcClient`, use `client.core` for these
55
+ shapes or migrate its legacy top-level calls to gRPC or GraphQL.
56
+
57
+ ```typescript
58
+ const { objects } = await client.listOwnedObjects({
59
+ owner: '0x...',
60
+ include: { display: true },
61
+ });
62
+
63
+ const result = await client.signAndExecuteTransaction({
64
+ transaction,
65
+ signer,
66
+ include: { effects: true, balanceChanges: true },
67
+ });
41
68
  ```
42
69
 
43
- ## Native vs core API
70
+ Common top-level methods include:
71
+
72
+ | Category | Methods |
73
+ | -------------- | ----------------------------------------------------------------------------------------------------------------- |
74
+ | Objects | `getObject`, `getObjects`, `listOwnedObjects`, `listDynamicFields`, `getDynamicField` |
75
+ | Coins | `listCoins`, `getBalance`, `listBalances`, `getCoinMetadata` |
76
+ | Transactions | `getTransaction`, `executeTransaction`, `signAndExecuteTransaction`, `waitForTransaction` |
77
+ | Simulation | `simulateTransaction` |
78
+ | Queries | `listTransactions`, `listEvents` |
79
+ | Move and names | `getMoveFunction`, `resolveNameServiceAddress`, `defaultNameServiceName`, `mvr.resolvePackage`, `mvr.resolveType` |
80
+ | Verification | `verifyZkLoginSignature` |
81
+
82
+ ### Core API
83
+
84
+ Use `client.core` when building SDKs or libraries that accept any client implementing
85
+ `ClientWithCoreApi`. The Core API is the shared contract that `SuiGrpcClient`, `SuiGraphQLClient`,
86
+ and the deprecated `SuiJsonRpcClient` implement.
87
+
88
+ ```typescript
89
+
90
+ return client.core.getObject({
91
+ objectId,
92
+ include: { content: true },
93
+ });
94
+ }
95
+ ```
44
96
 
45
97
  ### Native API
46
98
 
47
99
  Each client exposes the full capabilities of its underlying transport. Use the native API when you
48
- need transport-specific features or want maximum control:
100
+ need transport-specific features or want maximum control.
49
101
 
50
102
  ```typescript
51
103
 
104
+ const grpcClient = new SuiGrpcClient({
105
+ network: 'mainnet',
106
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
107
+ });
108
+
52
109
  // gRPC - access various service clients to call any gRPC method
53
110
  const { response } = await grpcClient.stateService.listOwnedObjects({ owner: '0x...' });
54
111
 
112
+ const graphqlClient = new SuiGraphQLClient({
113
+ network: 'mainnet',
114
+ url: 'https://graphql.mainnet.sui.io/graphql',
115
+ });
116
+
55
117
  // GraphQL - write type-safe custom queries using the graphql function
56
118
  const result = await graphqlClient.query({
57
119
  query: graphql(`
@@ -60,25 +122,10 @@ const result = await graphqlClient.query({
60
122
  }
61
123
  `),
62
124
  });
63
-
64
- // JSON-RPC - call any JSON-RPC method
65
- const coins = await jsonRpcClient.getCoins({ owner: '0x...' });
66
- ```
67
-
68
- ### Core API
69
-
70
- All clients also implement the [Core API](/sui/clients/core) through `client.core`. This provides a
71
- consistent interface for common operations that works identically across all transports:
72
-
73
- ```typescript
74
- // These methods work the same on any client
75
- const { object } = await client.core.getObject({ objectId: '0x...' });
76
- const balance = await client.core.getBalance({ owner: '0x...' });
77
- await client.core.executeTransaction({ transaction, signatures });
78
125
  ```
79
126
 
80
- The Core API is essential for [building SDKs](/sui/sdk-building) that work with any client the user
81
- chooses.
127
+ For legacy JSON-RPC-only code, see the [`SuiJsonRpcClient` page](/sui/clients/json-rpc) and the
128
+ [JSON-RPC migration guide](/sui/migrations/sui-2.0/json-rpc-migration).
82
129
 
83
130
  ## Client extensions
84
131
 
@@ -1,13 +1,18 @@
1
1
  # SuiJsonRpcClient
2
2
 
3
- > Connect to Sui through JSON-RPC with SuiJsonRpcClient.
3
+ > Maintain legacy JSON-RPC code while migrating to SuiGrpcClient or SuiGraphQLClient
4
4
 
5
- > **Warning:** The Sui JSON-RPC API has been deprecated. We recommend migration to
6
- > [`SuiGrpcClient`](/sui/clients/grpc) or [`SuiGraphQLClient`](/sui/clients/graphql) as soon as
7
- > possible.
5
+ > **Warning:** JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use [`SuiGrpcClient`](/sui/clients/grpc)
6
+ > for most application code, or [`SuiGraphQLClient`](/sui/clients/graphql) for GraphQL-specific
7
+ > indexed queries.
8
8
 
9
- The `SuiJsonRpcClient` connects to a Sui network's JSON-RPC server. It implements the
10
- [Core API](/sui/clients/core), so it can be used with any SDK that accepts `ClientWithCoreApi`.
9
+ This page exists for maintaining legacy JSON-RPC code. New code should use
10
+ [`SuiGrpcClient`](/sui/clients/grpc) and its top-level methods by default. See
11
+ [Migrating from JSON-RPC](/sui/migrations/sui-2.0/json-rpc-migration) for replacement examples.
12
+
13
+ The `SuiJsonRpcClient` connects to a Sui network's JSON-RPC server. It also implements the
14
+ [Core API](/sui/clients/core), so SDKs that accept `ClientWithCoreApi` can support it during a
15
+ migration.
11
16
 
12
17
  ```typescript
13
18
 
@@ -22,9 +27,9 @@ const { object } = await client.core.getObject({ objectId: '0x...' });
22
27
 
23
28
  ## Connecting to a Sui network
24
29
 
25
- To establish a connection to a network, import `SuiJsonRpcClient` from `@mysten/sui/client` and pass
26
- the relevant URL to the `url` parameter. The following example establishes a connection to Devnet
27
- and get all `Coin<coin_type>` objects owned by an address.
30
+ To establish a legacy JSON-RPC connection, import `SuiJsonRpcClient` from `@mysten/sui/jsonRpc` and
31
+ pass the relevant URL to the `url` parameter. The following example establishes a connection to
32
+ Devnet and gets all `Coin<coin_type>` objects owned by an address.
28
33
 
29
34
  ```typescript
30
35
 
@@ -62,6 +67,7 @@ available in the RPC.
62
67
 
63
68
  const client = new SuiJsonRpcClient({
64
69
  url: 'https://fullnode.devnet.sui.io:443',
70
+ network: 'devnet',
65
71
  });
66
72
  // asynchronously call suix_getCommitteeInfo
67
73
  const committeeInfo = await client.call('suix_getCommitteeInfo', []);
@@ -72,20 +78,16 @@ For a full list of available RPC methods, see the
72
78
 
73
79
  ## Customizing the transport
74
80
 
75
- The `SuiJsonRpcClient` uses a `Transport` class to manage connections to the RPC node. The default
76
- `SuiHTTPTransport` (alias for `JsonRpcHTTPTransport`) makes both JSON RPC requests, as well as
77
- websocket requests for subscriptions. You can construct a custom transport instance if you need to
78
- pass any custom options, such as headers or timeout values.
81
+ The `SuiJsonRpcClient` uses a transport to manage connections to the RPC node. By default it creates
82
+ a `JsonRpcHTTPTransport` for HTTP JSON-RPC requests. You can construct a custom transport instance
83
+ if you need to pass options such as headers or a custom `fetch` implementation.
79
84
 
80
85
  ```typescript
81
86
 
82
87
  const client = new SuiJsonRpcClient({
88
+ network: 'devnet',
83
89
  transport: new JsonRpcHTTPTransport({
84
90
  url: 'https://fullnode.devnet.sui.io:443',
85
- websocket: {
86
- reconnectTimeout: 1000,
87
- url: 'wss://fullnode.devnet.sui.io:443',
88
- },
89
91
  rpc: {
90
92
  headers: {
91
93
  'x-custom-header': 'custom value',
@@ -150,8 +152,8 @@ const result = await client.executeTransactionBlock({
150
152
 
151
153
  #### Arguments
152
154
 
153
- - `transactionBlock`: either a Transaction or BCS serialized transaction data bytes as a Uint8Array
154
- or as a base-64 encoded string.
155
+ - `transactionBlock`: BCS serialized transaction data bytes as a `Uint8Array` or base64-encoded
156
+ string.
155
157
  - `signature`: A signature, or list of signatures committed to the intent message of the transaction
156
158
  data, as a base-64 encoded string.
157
159
  - `options`:
@@ -178,15 +180,14 @@ const result = await client.signAndExecuteTransaction({
178
180
  });
179
181
 
180
182
  // IMPORTANT: Always check the transaction status
181
- if (result.$kind === 'FailedTransaction') {
182
- throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
183
+ if (result.effects?.status.status === 'failure') {
184
+ throw new Error(`Transaction failed: ${result.effects.status.error}`);
183
185
  }
184
186
  ```
185
187
 
186
188
  #### Arguments
187
189
 
188
- - `transaction`: BCS serialized transaction data bytes as a Uint8Array or as a base-64 encoded
189
- string.
190
+ - `transaction`: A `Transaction` or BCS serialized transaction data bytes as a `Uint8Array`.
190
191
  - `signer`: A `Keypair` instance to sign the transaction
191
192
  - `options`:
192
193
  - `showBalanceChanges`: Whether to show balance_changes. Default to be False
@@ -208,15 +209,18 @@ const tx = new Transaction();
208
209
  const result = await client.signAndExecuteTransaction({
209
210
  transaction: tx,
210
211
  signer: keypair,
212
+ options: {
213
+ showEffects: true,
214
+ },
211
215
  });
212
216
 
213
217
  // Check transaction status
214
- if (result.$kind === 'FailedTransaction') {
215
- throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
218
+ if (result.effects?.status.status === 'failure') {
219
+ throw new Error(`Transaction failed: ${result.effects.status.error}`);
216
220
  }
217
221
 
218
222
  const transaction = await client.waitForTransaction({
219
- digest: result.Transaction.digest,
223
+ digest: result.digest,
220
224
  options: {
221
225
  showEffects: true,
222
226
  },