@mysten/sui 2.24.0 → 2.26.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 (77) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/bcs/bcs.d.mts +6 -6
  3. package/dist/client/core.d.mts.map +1 -1
  4. package/dist/client/core.mjs +4 -1
  5. package/dist/client/core.mjs.map +1 -1
  6. package/dist/client/errors.d.mts +31 -2
  7. package/dist/client/errors.d.mts.map +1 -1
  8. package/dist/client/errors.mjs +15 -13
  9. package/dist/client/errors.mjs.map +1 -1
  10. package/dist/client/index.d.mts +2 -2
  11. package/dist/client/index.mjs +2 -2
  12. package/dist/client/mvr.d.mts.map +1 -1
  13. package/dist/client/mvr.mjs +1 -0
  14. package/dist/client/mvr.mjs.map +1 -1
  15. package/dist/cryptography/signature.d.mts +6 -6
  16. package/dist/graphql/client.d.mts +5 -1
  17. package/dist/graphql/client.d.mts.map +1 -1
  18. package/dist/graphql/client.mjs +15 -2
  19. package/dist/graphql/client.mjs.map +1 -1
  20. package/dist/graphql/core.d.mts +4 -4
  21. package/dist/graphql/core.d.mts.map +1 -1
  22. package/dist/graphql/core.mjs +61 -18
  23. package/dist/graphql/core.mjs.map +1 -1
  24. package/dist/graphql/generated/tada-env.d.mts +16 -0
  25. package/dist/grpc/client.d.mts +5 -1
  26. package/dist/grpc/client.d.mts.map +1 -1
  27. package/dist/grpc/client.mjs +14 -2
  28. package/dist/grpc/client.mjs.map +1 -1
  29. package/dist/grpc/core.d.mts.map +1 -1
  30. package/dist/grpc/core.mjs +29 -12
  31. package/dist/grpc/core.mjs.map +1 -1
  32. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  33. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  34. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  35. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  36. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  37. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  38. package/dist/jsonRpc/client.d.mts.map +1 -1
  39. package/dist/jsonRpc/client.mjs +60 -15
  40. package/dist/jsonRpc/client.mjs.map +1 -1
  41. package/dist/jsonRpc/core.d.mts +1 -1
  42. package/dist/jsonRpc/core.d.mts.map +1 -1
  43. package/dist/jsonRpc/core.mjs +73 -22
  44. package/dist/jsonRpc/core.mjs.map +1 -1
  45. package/dist/transactions/Transaction.d.mts +6 -6
  46. package/dist/transactions/data/v1.d.mts +220 -220
  47. package/dist/transactions/data/v1.d.mts.map +1 -1
  48. package/dist/transactions/data/v2.d.mts +16 -16
  49. package/dist/transactions/data/v2.d.mts.map +1 -1
  50. package/dist/version.mjs +1 -1
  51. package/dist/version.mjs.map +1 -1
  52. package/dist/zklogin/bcs.d.mts +14 -14
  53. package/docs/bcs.md +2 -2
  54. package/docs/clients/core.md +150 -710
  55. package/docs/clients/executing.md +113 -0
  56. package/docs/clients/graphql.md +80 -70
  57. package/docs/clients/grpc.md +223 -208
  58. package/docs/clients/index.md +56 -67
  59. package/docs/clients/querying.md +539 -0
  60. package/docs/llms-index.md +6 -5
  61. package/docs/migrations/sui-2.0/json-rpc-migration.md +3 -1
  62. package/docs/transactions/signing-and-execution.md +8 -28
  63. package/package.json +1 -1
  64. package/src/client/core.ts +1 -0
  65. package/src/client/errors.ts +39 -23
  66. package/src/client/index.ts +9 -1
  67. package/src/client/mvr.ts +6 -0
  68. package/src/graphql/client.ts +29 -2
  69. package/src/graphql/core.ts +53 -16
  70. package/src/graphql/generated/schema.graphql +11 -1
  71. package/src/graphql/generated/tada-env.ts +20 -0
  72. package/src/grpc/client.ts +28 -2
  73. package/src/grpc/core.ts +90 -65
  74. package/src/jsonRpc/client.ts +15 -0
  75. package/src/jsonRpc/core.ts +102 -24
  76. package/src/version.ts +1 -1
  77. package/docs/clients/json-rpc.md +0 -243
@@ -1,243 +0,0 @@
1
- # SuiJsonRpcClient
2
-
3
- > Maintain legacy JSON-RPC code while migrating to SuiGrpcClient or SuiGraphQLClient
4
-
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
-
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.
16
-
17
- ```typescript
18
-
19
- const client = new SuiJsonRpcClient({
20
- url: getJsonRpcFullnodeUrl('mainnet'),
21
- network: 'mainnet',
22
- });
23
-
24
- // Use the Core API
25
- const { object } = await client.core.getObject({ objectId: '0x...' });
26
- ```
27
-
28
- ## Connecting to a Sui network
29
-
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.
33
-
34
- ```typescript
35
-
36
- // use getJsonRpcFullnodeUrl to define Devnet RPC location
37
- const rpcUrl = getJsonRpcFullnodeUrl('devnet');
38
-
39
- // create a client connected to devnet
40
- const client = new SuiJsonRpcClient({ url: rpcUrl, network: 'devnet' });
41
-
42
- // get coins owned by an address
43
- // replace <OWNER_ADDRESS> with actual address in the form of 0x123...
44
- await client.getCoins({
45
- owner: '<OWNER_ADDRESS>',
46
- });
47
- ```
48
-
49
- Network URLs:
50
-
51
- - `localnet`: `http://127.0.0.1:9000`
52
- - `devnet`: `https://fullnode.devnet.sui.io:443`
53
- - `testnet`: `https://fullnode.testnet.sui.io:443`
54
-
55
- For local development, you can run `cargo run --bin sui -- start --with-faucet --force-regenesis` to
56
- spin up a local network with a local validator, a Full node, and a faucet server. Refer to
57
- [the Local Network guide](https://docs.sui.io/guides/developer/getting-started/local-network) for
58
- more information.
59
-
60
- ## Manually calling unsupported RPC methods
61
-
62
- You can use `SuiJsonRpcClient` to call any RPC method the node you're connecting to exposes. Most
63
- RPC methods are built into `SuiJsonRpcClient`, but you can use `call` to leverage any methods
64
- available in the RPC.
65
-
66
- ```typescript
67
-
68
- const client = new SuiJsonRpcClient({
69
- url: 'https://fullnode.devnet.sui.io:443',
70
- network: 'devnet',
71
- });
72
- // asynchronously call suix_getCommitteeInfo
73
- const committeeInfo = await client.call('suix_getCommitteeInfo', []);
74
- ```
75
-
76
- For a full list of available RPC methods, see the
77
- [RPC documentation](https://docs.sui.io/references/sui-api).
78
-
79
- ## Customizing the transport
80
-
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.
84
-
85
- ```typescript
86
-
87
- const client = new SuiJsonRpcClient({
88
- network: 'devnet',
89
- transport: new JsonRpcHTTPTransport({
90
- url: 'https://fullnode.devnet.sui.io:443',
91
- rpc: {
92
- headers: {
93
- 'x-custom-header': 'custom value',
94
- },
95
- },
96
- }),
97
- });
98
- ```
99
-
100
- ## Pagination
101
-
102
- `SuiJsonRpcClient` exposes a number of RPC methods that return paginated results. These methods
103
- return a result object with 3 fields:
104
-
105
- - `data`: The list of results for the current page
106
- - `nextCursor`: A cursor pointing to the next page of results
107
- - `hasNextPage`: A boolean indicating whether there are more pages of results
108
-
109
- Some APIs also accept an `order` option that can be set to either `ascending` or `descending` to
110
- change the order in which the results are returned.
111
-
112
- You can pass the `nextCursor` to the `cursor` option of the RPC method to retrieve the next page,
113
- along with a `limit` to specify the page size:
114
-
115
- ```ts
116
- const page1 = await client.getCheckpoints({
117
- descendingOrder: false,
118
- limit: 10,
119
- });
120
-
121
- const page2 =
122
- page1.hasNextPage &&
123
- (await client.getCheckpoints({
124
- descendingOrder: false,
125
- cursor: page1.nextCursor,
126
- limit: 10,
127
- }));
128
- ```
129
-
130
- ## Methods
131
-
132
- In addition to the RPC methods mentioned above, `SuiJsonRpcClient` also exposes some methods for
133
- working with Transactions.
134
-
135
- ### `executeTransactionBlock`
136
-
137
- ```tsx
138
- const tx = new Transaction();
139
-
140
- // add transaction data to tx...
141
-
142
- const { bytes, signature } = await tx.sign({ client, signer: keypair });
143
-
144
- const result = await client.executeTransactionBlock({
145
- transactionBlock: bytes,
146
- signature,
147
- options: {
148
- showEffects: true,
149
- },
150
- });
151
- ```
152
-
153
- #### Arguments
154
-
155
- - `transactionBlock`: BCS serialized transaction data bytes as a `Uint8Array` or base64-encoded
156
- string.
157
- - `signature`: A signature, or list of signatures committed to the intent message of the transaction
158
- data, as a base-64 encoded string.
159
- - `options`:
160
- - `showBalanceChanges`: Whether to show balance_changes. Default to be False
161
- - `showEffects`: Whether to show transaction effects. Default to be False
162
- - `showEvents`: Whether to show transaction events. Default to be False
163
- - `showInput`: Whether to show transaction input data. Default to be False
164
- - `showObjectChanges`: Whether to show object_changes. Default to be False
165
- - `showRawInput`: Whether to show bcs-encoded transaction input data
166
-
167
- ### `signAndExecuteTransaction`
168
-
169
- ```tsx
170
- const tx = new Transaction();
171
-
172
- // add transaction data to tx...
173
-
174
- const result = await client.signAndExecuteTransaction({
175
- transaction: tx,
176
- signer: keypair,
177
- options: {
178
- showEffects: true,
179
- },
180
- });
181
-
182
- // IMPORTANT: Always check the transaction status
183
- if (result.effects?.status.status === 'failure') {
184
- throw new Error(`Transaction failed: ${result.effects.status.error}`);
185
- }
186
- ```
187
-
188
- #### Arguments
189
-
190
- - `transaction`: A `Transaction` or BCS serialized transaction data bytes as a `Uint8Array`.
191
- - `signer`: A `Keypair` instance to sign the transaction
192
- - `options`:
193
- - `showBalanceChanges`: Whether to show balance_changes. Default to be False
194
- - `showEffects`: Whether to show transaction effects. Default to be False
195
- - `showEvents`: Whether to show transaction events. Default to be False
196
- - `showInput`: Whether to show transaction input data. Default to be False
197
- - `showObjectChanges`: Whether to show object_changes. Default to be False
198
- - `showRawInput`: Whether to show bcs-encoded transaction input data
199
-
200
- ### `waitForTransaction`
201
-
202
- Wait for a transaction result to be available over the API. This can be used in conjunction with
203
- `signAndExecuteTransaction` to wait for the transaction to be available through the API. This
204
- currently polls the `getTransactionBlock` API to check for the transaction.
205
-
206
- ```tsx
207
- const tx = new Transaction();
208
-
209
- const result = await client.signAndExecuteTransaction({
210
- transaction: tx,
211
- signer: keypair,
212
- options: {
213
- showEffects: true,
214
- },
215
- });
216
-
217
- // Check transaction status
218
- if (result.effects?.status.status === 'failure') {
219
- throw new Error(`Transaction failed: ${result.effects.status.error}`);
220
- }
221
-
222
- const transaction = await client.waitForTransaction({
223
- digest: result.digest,
224
- options: {
225
- showEffects: true,
226
- },
227
- });
228
- ```
229
-
230
- #### Arguments
231
-
232
- - `digest`: the digest of the queried transaction
233
- - `signal`: An optional abort signal that can be used to cancel the request
234
- - `timeout`: The amount of time to wait for a transaction. Defaults to one minute.
235
- - `pollInterval`: The amount of time to wait between checks for the transaction. Defaults to 2
236
- seconds.
237
- - `options`:
238
- - `showBalanceChanges`: Whether to show balance_changes. Default to be False
239
- - `showEffects`: Whether to show transaction effects. Default to be False
240
- - `showEvents`: Whether to show transaction events. Default to be False
241
- - `showInput`: Whether to show transaction input data. Default to be False
242
- - `showObjectChanges`: Whether to show object_changes. Default to be False
243
- - `showRawInput`: Whether to show bcs-encoded transaction input data