@mysten/sui 2.23.2 → 2.25.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.
- package/CHANGELOG.md +67 -0
- package/README.md +9 -9
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/client/core.d.mts +1 -0
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +4 -1
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/mvr.d.mts.map +1 -1
- package/dist/client/mvr.mjs +1 -0
- package/dist/client/mvr.mjs.map +1 -1
- package/dist/client/types.d.mts +7 -0
- package/dist/client/types.d.mts.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/graphql/client.d.mts +6 -1
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +18 -2
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +5 -4
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +60 -14
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +8 -1
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +16 -0
- package/dist/grpc/client.d.mts +6 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +17 -2
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +1 -0
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +20 -0
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/jsonRpc/client.d.mts.map +1 -1
- package/dist/jsonRpc/client.mjs +60 -15
- package/dist/jsonRpc/client.mjs.map +1 -1
- package/dist/jsonRpc/core.d.mts +6 -1
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +25 -7
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/docs/bcs.md +2 -2
- package/docs/clients/core.md +151 -690
- package/docs/clients/executing.md +113 -0
- package/docs/clients/graphql.md +91 -46
- package/docs/clients/grpc.md +239 -142
- package/docs/clients/index.md +87 -51
- package/docs/clients/querying.md +539 -0
- package/docs/executors.md +28 -13
- package/docs/index.md +1 -1
- package/docs/llms-index.md +18 -17
- package/docs/migrations/sui-2.0/dapp-kit.md +3 -3
- package/docs/migrations/sui-2.0/deepbook-v3.md +2 -2
- package/docs/migrations/sui-2.0/index.md +46 -25
- package/docs/migrations/sui-2.0/json-rpc-migration.md +462 -284
- package/docs/migrations/sui-2.0/kiosk.md +10 -9
- package/docs/migrations/sui-2.0/sdk-maintainers.md +17 -11
- package/docs/migrations/sui-2.0/sui.md +47 -29
- package/docs/migrations/sui-2.0/suins.md +2 -2
- package/docs/migrations/sui-2.0/walrus.md +3 -3
- package/docs/migrations/sui-2.0/zksend.md +9 -8
- package/docs/sdk-building.md +7 -5
- package/docs/transactions/signing-and-execution.md +8 -28
- package/package.json +1 -1
- package/src/client/core.ts +5 -0
- package/src/client/mvr.ts +6 -0
- package/src/client/types.ts +11 -0
- package/src/graphql/client.ts +35 -2
- package/src/graphql/core.ts +57 -10
- package/src/graphql/generated/queries.ts +14 -0
- package/src/graphql/generated/schema.graphql +11 -1
- package/src/graphql/generated/tada-env.ts +20 -0
- package/src/graphql/queries/nameService.graphql +6 -0
- package/src/grpc/client.ts +34 -2
- package/src/grpc/core.ts +35 -0
- package/src/jsonRpc/client.ts +15 -0
- package/src/jsonRpc/core.ts +31 -6
- package/src/version.ts +1 -1
- package/docs/clients/json-rpc.md +0 -239
package/docs/clients/json-rpc.md
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
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
|