@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.
Files changed (86) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +9 -9
  3. package/dist/bcs/bcs.d.mts +6 -6
  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 +4 -1
  7. package/dist/client/core.mjs.map +1 -1
  8. package/dist/client/mvr.d.mts.map +1 -1
  9. package/dist/client/mvr.mjs +1 -0
  10. package/dist/client/mvr.mjs.map +1 -1
  11. package/dist/client/types.d.mts +7 -0
  12. package/dist/client/types.d.mts.map +1 -1
  13. package/dist/cryptography/signature.d.mts +6 -6
  14. package/dist/graphql/client.d.mts +6 -1
  15. package/dist/graphql/client.d.mts.map +1 -1
  16. package/dist/graphql/client.mjs +18 -2
  17. package/dist/graphql/client.mjs.map +1 -1
  18. package/dist/graphql/core.d.mts +5 -4
  19. package/dist/graphql/core.d.mts.map +1 -1
  20. package/dist/graphql/core.mjs +60 -14
  21. package/dist/graphql/core.mjs.map +1 -1
  22. package/dist/graphql/generated/queries.d.mts.map +1 -1
  23. package/dist/graphql/generated/queries.mjs +8 -1
  24. package/dist/graphql/generated/queries.mjs.map +1 -1
  25. package/dist/graphql/generated/tada-env.d.mts +16 -0
  26. package/dist/grpc/client.d.mts +6 -1
  27. package/dist/grpc/client.d.mts.map +1 -1
  28. package/dist/grpc/client.mjs +17 -2
  29. package/dist/grpc/client.mjs.map +1 -1
  30. package/dist/grpc/core.d.mts +1 -0
  31. package/dist/grpc/core.d.mts.map +1 -1
  32. package/dist/grpc/core.mjs +20 -0
  33. package/dist/grpc/core.mjs.map +1 -1
  34. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  35. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  36. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  37. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  38. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  39. package/dist/jsonRpc/client.d.mts.map +1 -1
  40. package/dist/jsonRpc/client.mjs +60 -15
  41. package/dist/jsonRpc/client.mjs.map +1 -1
  42. package/dist/jsonRpc/core.d.mts +6 -1
  43. package/dist/jsonRpc/core.d.mts.map +1 -1
  44. package/dist/jsonRpc/core.mjs +25 -7
  45. package/dist/jsonRpc/core.mjs.map +1 -1
  46. package/dist/version.mjs +1 -1
  47. package/dist/version.mjs.map +1 -1
  48. package/dist/zklogin/bcs.d.mts +14 -14
  49. package/docs/bcs.md +2 -2
  50. package/docs/clients/core.md +151 -690
  51. package/docs/clients/executing.md +113 -0
  52. package/docs/clients/graphql.md +91 -46
  53. package/docs/clients/grpc.md +239 -142
  54. package/docs/clients/index.md +87 -51
  55. package/docs/clients/querying.md +539 -0
  56. package/docs/executors.md +28 -13
  57. package/docs/index.md +1 -1
  58. package/docs/llms-index.md +18 -17
  59. package/docs/migrations/sui-2.0/dapp-kit.md +3 -3
  60. package/docs/migrations/sui-2.0/deepbook-v3.md +2 -2
  61. package/docs/migrations/sui-2.0/index.md +46 -25
  62. package/docs/migrations/sui-2.0/json-rpc-migration.md +462 -284
  63. package/docs/migrations/sui-2.0/kiosk.md +10 -9
  64. package/docs/migrations/sui-2.0/sdk-maintainers.md +17 -11
  65. package/docs/migrations/sui-2.0/sui.md +47 -29
  66. package/docs/migrations/sui-2.0/suins.md +2 -2
  67. package/docs/migrations/sui-2.0/walrus.md +3 -3
  68. package/docs/migrations/sui-2.0/zksend.md +9 -8
  69. package/docs/sdk-building.md +7 -5
  70. package/docs/transactions/signing-and-execution.md +8 -28
  71. package/package.json +1 -1
  72. package/src/client/core.ts +5 -0
  73. package/src/client/mvr.ts +6 -0
  74. package/src/client/types.ts +11 -0
  75. package/src/graphql/client.ts +35 -2
  76. package/src/graphql/core.ts +57 -10
  77. package/src/graphql/generated/queries.ts +14 -0
  78. package/src/graphql/generated/schema.graphql +11 -1
  79. package/src/graphql/generated/tada-env.ts +20 -0
  80. package/src/graphql/queries/nameService.graphql +6 -0
  81. package/src/grpc/client.ts +34 -2
  82. package/src/grpc/core.ts +35 -0
  83. package/src/jsonRpc/client.ts +15 -0
  84. package/src/jsonRpc/core.ts +31 -6
  85. package/src/version.ts +1 -1
  86. package/docs/clients/json-rpc.md +0 -239
@@ -0,0 +1,113 @@
1
+ # Executing Transactions
2
+
3
+ > Simulate, execute, and wait for transactions with any Sui client
4
+
5
+ Executing a transaction is a client operation, and every client exposes the same four methods for
6
+ it. Building transactions is covered in [Building transactions](/sui/transactions/basics), and the
7
+ ways to obtain a signature (keypairs, wallets, sponsorship) in
8
+ [Signing and execution](/sui/transactions/signing-and-execution).
9
+
10
+ ## `signAndExecuteTransaction`
11
+
12
+ Signs with the given signer and executes, in one call:
13
+
14
+ ```typescript
15
+
16
+ const client = new SuiGrpcClient({
17
+ network: 'mainnet',
18
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
19
+ });
20
+
21
+ const result = await client.signAndExecuteTransaction({
22
+ transaction: tx,
23
+ signer: keypair,
24
+ include: { effects: true },
25
+ });
26
+ ```
27
+
28
+ The signer can be any `Signer`, such as a keypair or a KMS or Ledger signer. Pass
29
+ `additionalSignatures` for transactions needing more than one, such as a sponsored transaction the
30
+ sponsor has already signed.
31
+
32
+ ## `executeTransaction`
33
+
34
+ When you already have signed bytes, execute them directly:
35
+
36
+ ```typescript
37
+ const result = await client.executeTransaction({
38
+ transaction: bytes, // Uint8Array
39
+ signatures: [signature], // string[]
40
+ include: { effects: true, events: true },
41
+ });
42
+ ```
43
+
44
+ Both methods return a discriminated union rather than throwing on failure: a transaction that
45
+ executed but aborted onchain comes back as `FailedTransaction`.
46
+
47
+ ```typescript
48
+ const transaction = result.Transaction ?? result.FailedTransaction;
49
+
50
+ console.log(transaction.digest, transaction.status.success);
51
+ ```
52
+
53
+ A resolved promise means the network executed the transaction, which is not the same as it having
54
+ succeeded. See
55
+ [checking success or failure](/sui/transactions/signing-and-execution#checking-success-or-failure)
56
+ for handling both outcomes.
57
+
58
+ ## Include options
59
+
60
+ Execution, simulation, and [`getTransaction`](/sui/clients/querying#gettransaction) share one set of
61
+ `include` options. Everything is off by default, and a field that you did not request is typed
62
+ `undefined`:
63
+
64
+ | Option | Description |
65
+ | ---------------- | ------------------------------------------------------------------ |
66
+ | `effects` | Execution effects: created, mutated, and deleted objects, gas used |
67
+ | `events` | Move events emitted during execution |
68
+ | `transaction` | The full transaction data (sender, gas config, inputs, commands) |
69
+ | `balanceChanges` | Balance changes for each affected address and coin type |
70
+ | `objectTypes` | Map of object ID to type for all changed objects |
71
+ | `bcs` | Raw BCS-encoded transaction bytes |
72
+
73
+ ## `waitForTransaction`
74
+
75
+ Reads are served from indexed state, which trails execution slightly. Wait before reading a
76
+ transaction's effects back, or before submitting a transaction that depends on objects it touched:
77
+
78
+ ```typescript
79
+ const result = await client.signAndExecuteTransaction({ transaction: tx, signer: keypair });
80
+
81
+ await client.waitForTransaction({ result });
82
+
83
+ // Reads now reflect the transaction's effects
84
+ const { balance } = await client.getBalance({ owner: myAddress });
85
+ ```
86
+
87
+ It also accepts a `digest` instead of a result, along with `timeout` and a `pollSchedule` array of
88
+ backoff delays.
89
+
90
+ ## `simulateTransaction`
91
+
92
+ Dry-run a transaction without executing it, to estimate gas, inspect return values, or validate it
93
+ before asking anyone to sign:
94
+
95
+ ```typescript
96
+ const result = await client.simulateTransaction({
97
+ transaction: tx,
98
+ include: {
99
+ effects: true,
100
+ balanceChanges: true,
101
+ commandResults: true,
102
+ },
103
+ });
104
+ ```
105
+
106
+ Simulation takes the same include options plus `commandResults`, which returns each command's return
107
+ values and mutated references as BCS-encoded bytes for you to decode with the [BCS library](/bcs).
108
+ Two further options change how the node runs the simulation:
109
+
110
+ | Option | Effect |
111
+ | ---------------- | ---------------------------------------------------------------------------------------------------------------------- |
112
+ | `checksEnabled` | Set `false` to skip transaction validation, so non-public and non-entry functions can be inspected. Defaults to `true` |
113
+ | `doGasSelection` | Overrides whether the server selects gas payment during the simulation |
@@ -1,37 +1,44 @@
1
1
  # SuiGraphQLClient
2
2
 
3
- > Connect to Sui through GraphQL with SuiGraphQLClient.
3
+ > Connect to Sui over GraphQL and write type-safe custom queries
4
4
 
5
- The `SuiGraphQLClient` enables type-safe GraphQL queries against the Sui GraphQL API.
6
-
7
- For more details on the Sui GraphQL API, see the
8
- [GraphQL reference](https://docs.sui.io/references/sui-graphql).
9
-
10
- The `SuiGraphQLClient` implements all the the [Core API](/sui/clients/core) methods:
5
+ `SuiGraphQLClient` talks to the Sui GraphQL API. It implements the same client API as
6
+ `SuiGrpcClient`, so anything on [Querying data](/sui/clients/querying) and
7
+ [Signing and execution](/sui/transactions/signing-and-execution) works here unchanged:
11
8
 
12
9
  ```typescript
13
10
 
14
11
  const client = new SuiGraphQLClient({
15
- url: 'https://sui-mainnet.mystenlabs.com/graphql',
12
+ url: 'https://graphql.mainnet.sui.io/graphql',
16
13
  network: 'mainnet',
17
14
  });
18
15
 
19
- const { object } = await client.getObject({ objectId: '0x...' });
16
+ const { object } = await client.getObject({
17
+ objectId: '0x...',
18
+ include: { content: true },
19
+ });
20
20
  ```
21
21
 
22
- ## Custom GraphQL queries
22
+ Beyond that shared surface, the client can run any query the schema supports, typed from the schema
23
+ itself. The rest of this page covers writing those queries; see the
24
+ [GraphQL reference](https://docs.sui.io/references/sui-graphql) for the schema.
23
25
 
24
- To query anything no in the Core API, you can use the `query` method to execute custom GraphQL
25
- queries.
26
+ The constructor takes:
26
27
 
27
- We'll start by creating our client, and executing a very basic query:
28
+ | Option | Description |
29
+ | --------- | -------------------------------------------------------------- |
30
+ | `url` | GraphQL endpoint |
31
+ | `network` | Network the endpoint serves, used for caching and MVR defaults |
32
+ | `headers` | Extra headers sent with every request, such as an API key |
33
+ | `fetch` | Custom `fetch` implementation |
34
+ | `queries` | Named documents callable through [`execute`](#named-queries) |
35
+ | `mvr` | Move Registry overrides |
28
36
 
29
- ```typescript
37
+ ## Writing queries
30
38
 
31
- const gqlClient = new SuiGraphQLClient({
32
- url: 'https://graphql.testnet.sui.io/graphql',
33
- network: 'testnet',
34
- });
39
+ Use `query` to run any GraphQL document against the endpoint:
40
+
41
+ ```typescript
35
42
 
36
43
  const chainIdentifierQuery = graphql(`
37
44
  query {
@@ -39,53 +46,45 @@ const chainIdentifierQuery = graphql(`
39
46
  }
40
47
  `);
41
48
 
42
- async function getChainIdentifier() {
43
- const result = await gqlClient.query({
44
- query: chainIdentifierQuery,
45
- });
49
+ const result = await client.query({ query: chainIdentifierQuery });
46
50
 
47
- return result.data?.chainIdentifier;
48
- }
51
+ console.log(result.data?.chainIdentifier);
49
52
  ```
50
53
 
51
- ## Type-safety for GraphQL queries
54
+ ### Type safety
52
55
 
53
- You might have noticed the example above does not include any type definitions for the query. The
54
- `graphql` function used in the example is powered by [`gql.tada`](https://gql-tada.0no.co/) and will
55
- automatically provide the required type information to ensure that your queries are properly typed
56
- when executed through `SuiGraphQLClient`.
57
-
58
- The `graphql` function detects variables used by your query, and will ensure that the variables
59
- passed to your query are properly typed.
56
+ The `graphql` function is powered by [`gql.tada`](https://gql-tada.0no.co/), which types results and
57
+ variables from the schema itself, with no code generation step and no hand-written result types.
58
+ Fields you did not select are not on the result type, and variables are checked against the query:
60
59
 
61
60
  ```typescript
62
61
  const getSuinsName = graphql(`
63
62
  query getSuiName($address: SuiAddress!) {
64
63
  address(address: $address) {
65
- defaultSuinsName
64
+ defaultNameRecord {
65
+ domain
66
+ }
66
67
  }
67
68
  }
68
69
  `);
69
70
 
70
71
  async function getDefaultSuinsName(address: string) {
71
- const result = await gqlClient.query({
72
+ const result = await client.query({
72
73
  query: getSuinsName,
73
- variables: {
74
- address,
75
- },
74
+ variables: { address },
76
75
  });
77
76
 
78
- return result.data?.address?.defaultSuinsName;
77
+ return result.data?.address?.defaultNameRecord?.domain;
79
78
  }
80
79
  ```
81
80
 
82
- ## Using typed GraphQL queries with other GraphQL clients
81
+ ### Using typed documents with other clients
83
82
 
84
- The `graphql` function returns document nodes that implement the
85
- [`TypedDocumentNode`](https://github.com/dotansimha/graphql-typed-document-node) standard, and will
86
- work with the majority of popular GraphQL clients to provide queries that are automatically typed.
83
+ The `graphql` function returns document nodes implementing the
84
+ [`TypedDocumentNode`](https://github.com/dotansimha/graphql-typed-document-node) standard, so the
85
+ same typed documents work with most GraphQL clients:
87
86
 
88
- ```typescript
87
+ ```tsx
89
88
 
90
89
  const chainIdentifierQuery = graphql(`
91
90
  query {
@@ -94,8 +93,54 @@ const chainIdentifierQuery = graphql(`
94
93
  `);
95
94
 
96
95
  function ChainIdentifier() {
97
- const { loading, error, data } = useQuery(getPokemonsQuery);
96
+ // Result types flow through the other client's own hooks and methods
97
+ const { data } = useQuery(chainIdentifierQuery);
98
98
 
99
- return <div>{data?.chainIdentifier}</div>;
99
+ return <span>{data?.chainIdentifier}</span>;
100
100
  }
101
- ```
101
+ ```
102
+
103
+ ### Handling errors
104
+
105
+ `query` returns `{ data, errors }` rather than throwing on GraphQL errors, because a response can be
106
+ partially successful, where some fields resolve and others fail. Check `errors` before trusting
107
+ `data`:
108
+
109
+ ```typescript
110
+ const { data, errors } = await client.query({ query: chainIdentifierQuery });
111
+
112
+ if (errors?.length) {
113
+ throw new AggregateError(errors.map((error) => new Error(error.message)));
114
+ }
115
+ ```
116
+
117
+ A transport-level failure (a non-2xx response) throws `SuiGraphQLRequestError` instead.
118
+
119
+ ### Named queries
120
+
121
+ Pass a `queries` map when constructing the client and call them by name with `execute`. This keeps
122
+ query documents in one place instead of threading them through your call sites:
123
+
124
+ ```typescript
125
+ const client = new SuiGraphQLClient({
126
+ url: 'https://graphql.mainnet.sui.io/graphql',
127
+ network: 'mainnet',
128
+ queries: {
129
+ getSuinsName,
130
+ chainIdentifier: chainIdentifierQuery,
131
+ },
132
+ });
133
+
134
+ const result = await client.execute('getSuinsName', {
135
+ variables: { address: '0xabc...' },
136
+ });
137
+ ```
138
+
139
+ Results and variables stay typed from the document the name resolves to.
140
+
141
+ ## Reading your own writes
142
+
143
+ GraphQL reads an index that trails execution slightly, so a transaction `executeTransaction` has
144
+ already returned might not appear in a query for a moment. Use
145
+ [`waitForTransaction`](/sui/clients/executing#waitfortransaction) before reading back a
146
+ transaction's effects.