@mysten/sui 2.16.1 → 2.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/bcs/bcs.d.mts +6 -6
  3. package/dist/client/core-resolver.mjs +21 -12
  4. package/dist/client/core-resolver.mjs.map +1 -1
  5. package/dist/cryptography/signature.d.mts +6 -6
  6. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  7. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  8. package/dist/transactions/Transaction.d.mts +6 -6
  9. package/dist/version.mjs +1 -1
  10. package/dist/version.mjs.map +1 -1
  11. package/dist/zklogin/bcs.d.mts +14 -14
  12. package/dist/zklogin/bcs.d.mts.map +1 -1
  13. package/docs/bcs.md +134 -0
  14. package/docs/clients/core.md +622 -0
  15. package/docs/clients/graphql.md +101 -0
  16. package/docs/clients/grpc.md +210 -0
  17. package/docs/clients/index.md +95 -0
  18. package/docs/clients/json-rpc.md +239 -0
  19. package/docs/cryptography/keypairs.md +267 -0
  20. package/docs/cryptography/multisig.md +194 -0
  21. package/docs/cryptography/passkey.md +112 -0
  22. package/docs/cryptography/webcrypto-signer.md +81 -0
  23. package/docs/executors.md +150 -0
  24. package/docs/faucet.md +26 -0
  25. package/docs/hello-sui.md +115 -0
  26. package/docs/index.md +53 -0
  27. package/docs/install.md +61 -0
  28. package/docs/llm-docs.md +32 -0
  29. package/docs/llms-index.md +44 -0
  30. package/docs/migrations/0.38.md +58 -0
  31. package/docs/migrations/sui-1.0.md +455 -0
  32. package/docs/migrations/sui-2.0/agent-prompt.md +42 -0
  33. package/docs/migrations/sui-2.0/dapp-kit.md +350 -0
  34. package/docs/migrations/sui-2.0/deepbook-v3.md +33 -0
  35. package/docs/migrations/sui-2.0/index.md +158 -0
  36. package/docs/migrations/sui-2.0/json-rpc-migration.md +408 -0
  37. package/docs/migrations/sui-2.0/kiosk.md +120 -0
  38. package/docs/migrations/sui-2.0/sdk-maintainers.md +90 -0
  39. package/docs/migrations/sui-2.0/seal.md +14 -0
  40. package/docs/migrations/sui-2.0/sui.md +341 -0
  41. package/docs/migrations/sui-2.0/suins.md +44 -0
  42. package/docs/migrations/sui-2.0/wallet-builders.md +66 -0
  43. package/docs/migrations/sui-2.0/walrus.md +41 -0
  44. package/docs/migrations/sui-2.0/zksend.md +95 -0
  45. package/docs/plugins.md +258 -0
  46. package/docs/sdk-building.md +344 -0
  47. package/docs/transaction-building/basics.md +299 -0
  48. package/docs/transaction-building/gas.md +61 -0
  49. package/docs/transaction-building/intents.md +62 -0
  50. package/docs/transaction-building/offline.md +73 -0
  51. package/docs/transaction-building/sponsored-transactions.md +22 -0
  52. package/docs/utils/derived_objects.md +80 -0
  53. package/docs/utils/index.md +59 -0
  54. package/docs/zklogin.md +83 -0
  55. package/package.json +3 -3
  56. package/src/client/core-resolver.ts +48 -13
  57. package/src/version.ts +1 -1
@@ -0,0 +1,210 @@
1
+ # SuiGrpcClient
2
+
3
+ > Connect to Sui through gRPC with SuiGrpcClient.
4
+
5
+ The `SuiGrpcClient` provides access to the Full Node gRPC API.
6
+
7
+ For more complete details on what is available through this API see the
8
+ [gRPC API docs](https://docs.sui.io/develop/accessing-data/grpc/what-is-grpc).
9
+
10
+ ## Creating a gRPC client
11
+
12
+ To get started, create a `SuiGrpcClient` instance by specifying a network and base URL:
13
+
14
+ ```typescript
15
+
16
+ const grpcClient = new SuiGrpcClient({
17
+ network: 'testnet',
18
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
19
+ });
20
+ ```
21
+
22
+ For local development:
23
+
24
+ ```typescript
25
+ const grpcClient = new SuiGrpcClient({
26
+ network: 'localnet',
27
+ baseUrl: 'http://127.0.0.1:9000',
28
+ });
29
+ ```
30
+
31
+ ## Transport options
32
+
33
+ By default, `SuiGrpcClient` uses `GrpcWebFetchTransport` from
34
+ [protobuf-ts](https://github.com/timostamm/protobuf-ts), which works in browsers and Node.js through
35
+ the Fetch API. You can also provide a custom transport for advanced use cases.
36
+
37
+ The `GrpcWebFetchTransport` class, `GrpcWebOptions` type, and `RpcTransport` type are all
38
+ re-exported from `@mysten/sui/grpc` for convenience.
39
+
40
+ ### gRPC-web transport (default)
41
+
42
+ The default transport uses the gRPC-web protocol over HTTP/1.1 or HTTP/2. You can customize it by
43
+ passing `GrpcWebFetchTransport` options directly:
44
+
45
+ ```typescript
46
+
47
+ const transport = new GrpcWebFetchTransport({
48
+ baseUrl: 'https://your-custom-grpc-endpoint.com',
49
+ format: 'binary', // default is 'text' (base64-encoded)
50
+ // Additional transport options like fetchInit
51
+ });
52
+
53
+ const grpcClient = new SuiGrpcClient({
54
+ network: 'testnet',
55
+ transport,
56
+ });
57
+ ```
58
+
59
+ ### Native gRPC transport
60
+
61
+ For server-side applications (Node.js, Bun, and others), you can use the native gRPC transport with
62
+ `@protobuf-ts/grpc-transport` and `@grpc/grpc-js`. This uses HTTP/2 with the native gRPC protocol
63
+ rather than the gRPC-web translation layer.
64
+
65
+ Install the required packages:
66
+
67
+ ```bash
68
+ npm install @protobuf-ts/grpc-transport @grpc/grpc-js
69
+ ```
70
+
71
+ Then create the client with a `GrpcTransport`:
72
+
73
+ ```typescript
74
+
75
+ const transport = new GrpcTransport({
76
+ host: 'fullnode.testnet.sui.io:443',
77
+ channelCredentials: ChannelCredentials.createSsl(),
78
+ });
79
+
80
+ const grpcClient = new SuiGrpcClient({
81
+ network: 'testnet',
82
+ transport,
83
+ });
84
+ ```
85
+
86
+ For local development without TLS:
87
+
88
+ ```typescript
89
+
90
+ const transport = new GrpcTransport({
91
+ host: '127.0.0.1:9000',
92
+ channelCredentials: ChannelCredentials.createInsecure(),
93
+ });
94
+
95
+ const grpcClient = new SuiGrpcClient({
96
+ network: 'localnet',
97
+ transport,
98
+ });
99
+ ```
100
+
101
+ ## Using service clients
102
+
103
+ The `SuiGrpcClient` exposes several service clients for lower-level access to the gRPC API. These
104
+ service clients are generated using [protobuf-ts](https://github.com/timostamm/protobuf-ts), which
105
+ provides type-safe gRPC clients for TypeScript. For more details on how to use gRPC with Sui, see
106
+ the [gRPC overview](https://docs.sui.io/develop/accessing-data/grpc/what-is-grpc).
107
+
108
+ ### With the core API
109
+
110
+ The gRPC client implements all the [`core`](./core) API methods:
111
+
112
+ ```typescript
113
+
114
+ const grpcClient = new SuiGrpcClient({
115
+ network: 'testnet',
116
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
117
+ });
118
+ // Get coins owned by an address
119
+ await grpcClient.getCoins({
120
+ owner: '<OWNER_ADDRESS>',
121
+ });
122
+ ```
123
+
124
+ To query additional data not available in the core API, you can use the service clients directly:
125
+
126
+ ### Transaction execution service
127
+
128
+ ```typescript
129
+ const { response } = await grpcClient.transactionExecutionService.executeTransaction({
130
+ transaction: {
131
+ bcs: {
132
+ value: transactionBytes,
133
+ },
134
+ },
135
+ signatures: signatures.map((sig) => ({
136
+ bcs: { value: fromBase64(sig) },
137
+ signature: { oneofKind: undefined },
138
+ })),
139
+ });
140
+
141
+ // IMPORTANT: Always check the transaction status
142
+ if (!response.finality?.effects?.status?.success) {
143
+ const error = response.finality?.effects?.status?.error;
144
+ throw new Error(`Transaction failed: ${error || 'Unknown error'}`);
145
+ }
146
+ ```
147
+
148
+ ### Ledger service
149
+
150
+ ```typescript
151
+ // Get transaction by digest
152
+ const { response } = await grpcClient.ledgerService.getTransaction({
153
+ digest: '0x123...',
154
+ });
155
+
156
+ // Get current epoch information
157
+ const { response: epochInfo } = await grpcClient.ledgerService.getEpoch({});
158
+ ```
159
+
160
+ ### State service
161
+
162
+ ```typescript
163
+ // List owned objects
164
+ const { response } = await grpcClient.stateService.listOwnedObjects({
165
+ owner: '0xabc...',
166
+ objectType: '0x2::coin::Coin<0x2::sui::SUI>',
167
+ });
168
+
169
+ // Get dynamic fields
170
+ const { response: fields } = await grpcClient.stateService.listDynamicFields({
171
+ parent: '0x123...',
172
+ });
173
+ ```
174
+
175
+ ### Move package service
176
+
177
+ ```typescript
178
+ // Get function information
179
+ const { response } = await grpcClient.movePackageService.getFunction({
180
+ packageId: '0x2',
181
+ moduleName: 'coin',
182
+ name: 'transfer',
183
+ });
184
+ ```
185
+
186
+ ### Name service
187
+
188
+ ```typescript
189
+ // Reverse lookup address to get name
190
+ const { response } = await grpcClient.nameService.reverseLookupName({
191
+ address: '0xabc...',
192
+ });
193
+ ```
194
+
195
+ ### Signature verification service
196
+
197
+ ```typescript
198
+ // Verify a signature
199
+ const { response } = await grpcClient.signatureVerificationService.verifySignature({
200
+ message: {
201
+ name: 'TransactionData',
202
+ value: messageBytes,
203
+ },
204
+ signature: {
205
+ bcs: { value: signatureBytes },
206
+ signature: { oneofKind: undefined },
207
+ },
208
+ jwks: [],
209
+ });
210
+ ```
@@ -0,0 +1,95 @@
1
+ # Sui Clients
2
+
3
+ > Choose and configure gRPC, GraphQL, or JSON-RPC clients for the Sui network.
4
+
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:
7
+
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
10
+
11
+ ## Available clients
12
+
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
+
19
+ All clients are compatible with Mysten SDKs like `@mysten/walrus`, `@mysten/seal` and
20
+ `@mysten/suins`.
21
+
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
+
27
+ ## Quick start
28
+
29
+ ```typescript
30
+
31
+ const client = new SuiGrpcClient({
32
+ network: 'mainnet',
33
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
34
+ });
35
+
36
+ // Use the native API for full access to transport-specific features
37
+ const { response } = await client.ledgerService.getTransaction({ digest: '0x...' });
38
+
39
+ // Use the Core API for transport-agnostic operations
40
+ const { object } = await client.core.getObject({ objectId: '0x...' });
41
+ ```
42
+
43
+ ## Native vs core API
44
+
45
+ ### Native API
46
+
47
+ 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:
49
+
50
+ ```typescript
51
+
52
+ // gRPC - access various service clients to call any gRPC method
53
+ const { response } = await grpcClient.stateService.listOwnedObjects({ owner: '0x...' });
54
+
55
+ // GraphQL - write type-safe custom queries using the graphql function
56
+ const result = await graphqlClient.query({
57
+ query: graphql(`
58
+ query {
59
+ chainIdentifier
60
+ }
61
+ `),
62
+ });
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
+ ```
79
+
80
+ The Core API is essential for [building SDKs](/sui/sdk-building) that work with any client the user
81
+ chooses.
82
+
83
+ ## Client extensions
84
+
85
+ All clients support extensions through the `$extend` method, enabling SDKs like
86
+ [@mysten/walrus](https://www.npmjs.com/package/@mysten/walrus) to add functionality:
87
+
88
+ ```typescript
89
+
90
+ const client = new SuiGrpcClient({ network: 'mainnet', baseUrl: '...' }).$extend(walrus());
91
+
92
+ await client.walrus.writeBlob({ ... });
93
+ ```
94
+
95
+ See [Building SDKs](/sui/sdk-building) for more on creating client extensions.
@@ -0,0 +1,239 @@
1
+ # SuiJsonRpcClient
2
+
3
+ > Connect to Sui through JSON-RPC with SuiJsonRpcClient.
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.
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`.
11
+
12
+ ```typescript
13
+
14
+ const client = new SuiJsonRpcClient({
15
+ url: getJsonRpcFullnodeUrl('mainnet'),
16
+ network: 'mainnet',
17
+ });
18
+
19
+ // Use the Core API
20
+ const { object } = await client.core.getObject({ objectId: '0x...' });
21
+ ```
22
+
23
+ ## Connecting to a Sui network
24
+
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.
28
+
29
+ ```typescript
30
+
31
+ // use getJsonRpcFullnodeUrl to define Devnet RPC location
32
+ const rpcUrl = getJsonRpcFullnodeUrl('devnet');
33
+
34
+ // create a client connected to devnet
35
+ const client = new SuiJsonRpcClient({ url: rpcUrl, network: 'devnet' });
36
+
37
+ // get coins owned by an address
38
+ // replace <OWNER_ADDRESS> with actual address in the form of 0x123...
39
+ await client.getCoins({
40
+ owner: '<OWNER_ADDRESS>',
41
+ });
42
+ ```
43
+
44
+ Network URLs:
45
+
46
+ - `localnet`: `http://127.0.0.1:9000`
47
+ - `devnet`: `https://fullnode.devnet.sui.io:443`
48
+ - `testnet`: `https://fullnode.testnet.sui.io:443`
49
+
50
+ For local development, you can run `cargo run --bin sui -- start --with-faucet --force-regenesis` to
51
+ spin up a local network with a local validator, a Full node, and a faucet server. Refer to
52
+ [the Local Network guide](https://docs.sui.io/guides/developer/getting-started/local-network) for
53
+ more information.
54
+
55
+ ## Manually calling unsupported RPC methods
56
+
57
+ You can use `SuiJsonRpcClient` to call any RPC method the node you're connecting to exposes. Most
58
+ RPC methods are built into `SuiJsonRpcClient`, but you can use `call` to leverage any methods
59
+ available in the RPC.
60
+
61
+ ```typescript
62
+
63
+ const client = new SuiJsonRpcClient({
64
+ url: 'https://fullnode.devnet.sui.io:443',
65
+ });
66
+ // asynchronously call suix_getCommitteeInfo
67
+ const committeeInfo = await client.call('suix_getCommitteeInfo', []);
68
+ ```
69
+
70
+ For a full list of available RPC methods, see the
71
+ [RPC documentation](https://docs.sui.io/references/sui-api).
72
+
73
+ ## Customizing the transport
74
+
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.
79
+
80
+ ```typescript
81
+
82
+ const client = new SuiJsonRpcClient({
83
+ transport: new JsonRpcHTTPTransport({
84
+ url: 'https://fullnode.devnet.sui.io:443',
85
+ websocket: {
86
+ reconnectTimeout: 1000,
87
+ url: 'wss://fullnode.devnet.sui.io:443',
88
+ },
89
+ rpc: {
90
+ headers: {
91
+ 'x-custom-header': 'custom value',
92
+ },
93
+ },
94
+ }),
95
+ });
96
+ ```
97
+
98
+ ## Pagination
99
+
100
+ `SuiJsonRpcClient` exposes a number of RPC methods that return paginated results. These methods
101
+ return a result object with 3 fields:
102
+
103
+ - `data`: The list of results for the current page
104
+ - `nextCursor`: A cursor pointing to the next page of results
105
+ - `hasNextPage`: A boolean indicating whether there are more pages of results
106
+
107
+ Some APIs also accept an `order` option that can be set to either `ascending` or `descending` to
108
+ change the order in which the results are returned.
109
+
110
+ You can pass the `nextCursor` to the `cursor` option of the RPC method to retrieve the next page,
111
+ along with a `limit` to specify the page size:
112
+
113
+ ```ts
114
+ const page1 = await client.getCheckpoints({
115
+ descendingOrder: false,
116
+ limit: 10,
117
+ });
118
+
119
+ const page2 =
120
+ page1.hasNextPage &&
121
+ (await client.getCheckpoints({
122
+ descendingOrder: false,
123
+ cursor: page1.nextCursor,
124
+ limit: 10,
125
+ }));
126
+ ```
127
+
128
+ ## Methods
129
+
130
+ In addition to the RPC methods mentioned above, `SuiJsonRpcClient` also exposes some methods for
131
+ working with Transactions.
132
+
133
+ ### `executeTransactionBlock`
134
+
135
+ ```tsx
136
+ const tx = new Transaction();
137
+
138
+ // add transaction data to tx...
139
+
140
+ const { bytes, signature } = await tx.sign({ client, signer: keypair });
141
+
142
+ const result = await client.executeTransactionBlock({
143
+ transactionBlock: bytes,
144
+ signature,
145
+ options: {
146
+ showEffects: true,
147
+ },
148
+ });
149
+ ```
150
+
151
+ #### Arguments
152
+
153
+ - `transactionBlock`: either a Transaction or BCS serialized transaction data bytes as a Uint8Array
154
+ or as a base-64 encoded string.
155
+ - `signature`: A signature, or list of signatures committed to the intent message of the transaction
156
+ data, as a base-64 encoded string.
157
+ - `options`:
158
+ - `showBalanceChanges`: Whether to show balance_changes. Default to be False
159
+ - `showEffects`: Whether to show transaction effects. Default to be False
160
+ - `showEvents`: Whether to show transaction events. Default to be False
161
+ - `showInput`: Whether to show transaction input data. Default to be False
162
+ - `showObjectChanges`: Whether to show object_changes. Default to be False
163
+ - `showRawInput`: Whether to show bcs-encoded transaction input data
164
+
165
+ ### `signAndExecuteTransaction`
166
+
167
+ ```tsx
168
+ const tx = new Transaction();
169
+
170
+ // add transaction data to tx...
171
+
172
+ const result = await client.signAndExecuteTransaction({
173
+ transaction: tx,
174
+ signer: keypair,
175
+ options: {
176
+ showEffects: true,
177
+ },
178
+ });
179
+
180
+ // IMPORTANT: Always check the transaction status
181
+ if (result.$kind === 'FailedTransaction') {
182
+ throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
183
+ }
184
+ ```
185
+
186
+ #### Arguments
187
+
188
+ - `transaction`: BCS serialized transaction data bytes as a Uint8Array or as a base-64 encoded
189
+ string.
190
+ - `signer`: A `Keypair` instance to sign the transaction
191
+ - `options`:
192
+ - `showBalanceChanges`: Whether to show balance_changes. Default to be False
193
+ - `showEffects`: Whether to show transaction effects. Default to be False
194
+ - `showEvents`: Whether to show transaction events. Default to be False
195
+ - `showInput`: Whether to show transaction input data. Default to be False
196
+ - `showObjectChanges`: Whether to show object_changes. Default to be False
197
+ - `showRawInput`: Whether to show bcs-encoded transaction input data
198
+
199
+ ### `waitForTransaction`
200
+
201
+ Wait for a transaction result to be available over the API. This can be used in conjunction with
202
+ `signAndExecuteTransaction` to wait for the transaction to be available through the API. This
203
+ currently polls the `getTransactionBlock` API to check for the transaction.
204
+
205
+ ```tsx
206
+ const tx = new Transaction();
207
+
208
+ const result = await client.signAndExecuteTransaction({
209
+ transaction: tx,
210
+ signer: keypair,
211
+ });
212
+
213
+ // Check transaction status
214
+ if (result.$kind === 'FailedTransaction') {
215
+ throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
216
+ }
217
+
218
+ const transaction = await client.waitForTransaction({
219
+ digest: result.Transaction.digest,
220
+ options: {
221
+ showEffects: true,
222
+ },
223
+ });
224
+ ```
225
+
226
+ #### Arguments
227
+
228
+ - `digest`: the digest of the queried transaction
229
+ - `signal`: An optional abort signal that can be used to cancel the request
230
+ - `timeout`: The amount of time to wait for a transaction. Defaults to one minute.
231
+ - `pollInterval`: The amount of time to wait between checks for the transaction. Defaults to 2
232
+ seconds.
233
+ - `options`:
234
+ - `showBalanceChanges`: Whether to show balance_changes. Default to be False
235
+ - `showEffects`: Whether to show transaction effects. Default to be False
236
+ - `showEvents`: Whether to show transaction events. Default to be False
237
+ - `showInput`: Whether to show transaction input data. Default to be False
238
+ - `showObjectChanges`: Whether to show object_changes. Default to be False
239
+ - `showRawInput`: Whether to show bcs-encoded transaction input data