@mysten/docs 0.1.43 → 0.1.45

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.
@@ -1,12 +1,12 @@
1
1
  # Migrate to 2.0
2
2
 
3
- > Migration guide for Sui TypeScript SDK 2.0 covering all @mysten packages.
3
+ > Migration guide for Sui TypeScript SDK 2.0 covering all @mysten packages
4
4
 
5
5
  This guide covers the breaking changes across the latest release of all the `@mysten/*` packages.
6
6
 
7
- The primary goal of this release is to support the new GRPC and GraphQL APIs across all the mysten
8
- SDKs. These releases also include removals of deprecated APIs, some renaming for better consistency,
9
- and significant internal refactoring to improve maintainability. Starting with this release, Mysten
7
+ The primary goal of this release is to support the gRPC and GraphQL APIs across all Mysten SDKs.
8
+ These releases also include removals of deprecated APIs, some renaming for better consistency, and
9
+ significant internal refactoring to improve maintainability. Starting with this release, Mysten
10
10
  packages will now be published as ESM only packages.
11
11
 
12
12
  ## Quick reference
@@ -65,39 +65,51 @@ updates.
65
65
 
66
66
  ### Client migration
67
67
 
68
- The most common change across all SDKs is migrating from `SuiClient` to `SuiJsonRpcClient`:
68
+ The recommended app migration is to create one `SuiGrpcClient` and use its top-level methods:
69
69
 
70
70
  ```diff
71
71
  - import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
72
- + import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
72
+ + import { SuiGrpcClient } from '@mysten/sui/grpc';
73
73
 
74
74
  - const client = new SuiClient({ url: getFullnodeUrl('mainnet') });
75
- + const client = new SuiJsonRpcClient({
76
- + url: getJsonRpcFullnodeUrl('mainnet'),
75
+ + const client = new SuiGrpcClient({
76
+ + baseUrl: 'https://fullnode.mainnet.sui.io:443',
77
77
  + network: 'mainnet',
78
78
  + });
79
79
  ```
80
80
 
81
- We also recommend moving from the deprecated JSON RPC APIs to the new gRPC API as soon as possible:
81
+ Then migrate old JSON-RPC method names to the gRPC top-level methods:
82
82
 
83
83
  ```diff
84
- - import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
85
- + import { SuiGrpcClient } from '@mysten/sui/grpc';
84
+ - const coins = await client.getCoins({ owner });
85
+ + const coins = await client.listCoins({ owner });
86
+
87
+ - const txs = await client.queryTransactionBlocks({ filter, options });
88
+ + const txs = await client.listTransactions({ filter, include });
89
+
90
+ - const events = await client.queryEvents({ query, order: 'descending' });
91
+ + const events = await client.listEvents({ filter, order: 'descending' });
86
92
 
87
- - const client = new SuiJsonRpcClient({ url, network: 'mainnet' });
88
- + const client = new SuiGrpcClient({ baseUrl, network: 'mainnet' });
93
+ - const transaction = await client.getTransactionBlock({ digest, options });
94
+ + const transaction = await client.getTransaction({ digest, include });
89
95
  ```
90
96
 
91
- The gRPC runs on full nodes so in most cases you should be able to use the same URLs when migrating
92
- to gRPC.
97
+ The gRPC API runs on full nodes, so in most cases you can use the same full node host when migrating
98
+ from JSON-RPC to gRPC. Standard transaction and event queries are top-level methods on both
99
+ `SuiGrpcClient` and `SuiGraphQLClient`. Use custom GraphQL queries for indexed data, historical
100
+ object versions, or selection sets that are not covered by the shared methods.
101
+
102
+ `SuiJsonRpcClient` still exists under `@mysten/sui/jsonRpc` for legacy code, but JSON-RPC APIs are
103
+ deprecated in the Sui TypeScript SDK. See
104
+ [Migrating from JSON-RPC](/sui/migrations/sui-2.0/json-rpc-migration) for detailed replacements.
93
105
 
94
106
  ### Network parameter required
95
107
 
96
108
  All client constructors now require an explicit `network` parameter:
97
109
 
98
110
  ```ts
99
- const client = new SuiJsonRpcClient({
100
- url: getJsonRpcFullnodeUrl('mainnet'),
111
+ const grpcClient = new SuiGrpcClient({
112
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
101
113
  network: 'mainnet', // Required
102
114
  });
103
115
 
@@ -106,23 +118,32 @@ const graphqlClient = new SuiGraphQLClient({
106
118
  network: 'mainnet', // Required
107
119
  });
108
120
 
109
- const grpcClient = new SuiGrpcClient({
110
- baseUrl: 'https://fullnode.mainnet.sui.io:443',
121
+ const jsonRpcClient = new SuiJsonRpcClient({
122
+ url: 'https://fullnode.mainnet.sui.io:443',
111
123
  network: 'mainnet', // Required
112
124
  });
113
125
  ```
114
126
 
115
127
  ### `ClientWithCoreApi` Interface
116
128
 
117
- Many SDK methods now accept any client implementing `ClientWithCoreApi`, enabling use with JSON-RPC,
118
- GraphQL, or gRPC transports:
129
+ Many SDK methods now accept any client implementing `ClientWithCoreApi`. SDKs use
130
+ `client.core.<method>()` so they can work across `SuiGrpcClient`, `SuiGraphQLClient`, and the
131
+ deprecated `SuiJsonRpcClient` while apps keep using the top-level methods on their chosen client:
119
132
 
120
133
  ```ts
121
134
 
122
- // All of these work with APIs that accept ClientWithCoreApi
123
- const jsonRpcClient = new SuiJsonRpcClient({ url, network: 'mainnet' });
124
- const graphqlClient = new SuiGraphQLClient({ url, network: 'mainnet' });
125
- const grpcClient = new SuiGrpcClient({ baseUrl, network: 'mainnet' });
135
+ const client = new SuiGrpcClient({
136
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
137
+ network: 'mainnet',
138
+ });
139
+
140
+ // App code: use top-level methods.
141
+ const { balance } = await client.getBalance({ owner });
142
+
143
+ // SDK code: accept ClientWithCoreApi and use client.core.
144
+ async function readForSdk(client: ClientWithCoreApi, objectId: string) {
145
+ return client.core.getObject({ objectId });
146
+ }
126
147
  ```
127
148
 
128
149
  ## Package-specific guides