@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
|
@@ -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 |
|
package/docs/clients/graphql.md
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
# SuiGraphQLClient
|
|
2
2
|
|
|
3
|
-
> Connect to Sui
|
|
3
|
+
> Connect to Sui over GraphQL and write type-safe custom queries
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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://
|
|
12
|
+
url: 'https://graphql.mainnet.sui.io/graphql',
|
|
16
13
|
network: 'mainnet',
|
|
17
14
|
});
|
|
18
15
|
|
|
19
|
-
const { object } = await client.getObject({
|
|
16
|
+
const { object } = await client.getObject({
|
|
17
|
+
objectId: '0x...',
|
|
18
|
+
include: { content: true },
|
|
19
|
+
});
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
queries.
|
|
26
|
+
The constructor takes:
|
|
26
27
|
|
|
27
|
-
|
|
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
|
-
|
|
37
|
+
## Writing queries
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
43
|
-
const result = await gqlClient.query({
|
|
44
|
-
query: chainIdentifierQuery,
|
|
45
|
-
});
|
|
49
|
+
const result = await client.query({ query: chainIdentifierQuery });
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
}
|
|
51
|
+
console.log(result.data?.chainIdentifier);
|
|
49
52
|
```
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
### Type safety
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
64
|
+
defaultNameRecord {
|
|
65
|
+
domain
|
|
66
|
+
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
`);
|
|
69
70
|
|
|
70
71
|
async function getDefaultSuinsName(address: string) {
|
|
71
|
-
const result = await
|
|
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?.
|
|
77
|
+
return result.data?.address?.defaultNameRecord?.domain;
|
|
79
78
|
}
|
|
80
79
|
```
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
### Using typed documents with other clients
|
|
83
82
|
|
|
84
|
-
The `graphql` function returns document nodes
|
|
85
|
-
[`TypedDocumentNode`](https://github.com/dotansimha/graphql-typed-document-node) standard,
|
|
86
|
-
|
|
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
|
-
```
|
|
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
|
-
|
|
96
|
+
// Result types flow through the other client's own hooks and methods
|
|
97
|
+
const { data } = useQuery(chainIdentifierQuery);
|
|
98
98
|
|
|
99
|
-
return <
|
|
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.
|