@mysten/sui 2.24.0 → 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 +60 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/index.d.mts +36 -36
- 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/cryptography/signature.d.mts +6 -6
- package/dist/graphql/client.d.mts +5 -1
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +15 -2
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +4 -4
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +50 -13
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +16 -0
- package/dist/grpc/client.d.mts +5 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +14 -2
- package/dist/grpc/client.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/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/grpc/proto/sui/rpc/v2/transaction_execution_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 +1 -1
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +18 -7
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +3 -3
- package/dist/transactions/data/v1.d.mts +220 -220
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.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 +150 -710
- package/docs/clients/executing.md +113 -0
- package/docs/clients/graphql.md +80 -70
- package/docs/clients/grpc.md +223 -208
- package/docs/clients/index.md +56 -67
- package/docs/clients/querying.md +539 -0
- package/docs/llms-index.md +6 -5
- package/docs/migrations/sui-2.0/json-rpc-migration.md +3 -1
- package/docs/transactions/signing-and-execution.md +8 -28
- package/package.json +1 -1
- package/src/client/core.ts +1 -0
- package/src/client/mvr.ts +6 -0
- package/src/graphql/client.ts +29 -2
- package/src/graphql/core.ts +42 -10
- package/src/graphql/generated/schema.graphql +11 -1
- package/src/graphql/generated/tada-env.ts +20 -0
- package/src/grpc/client.ts +28 -2
- package/src/jsonRpc/client.ts +15 -0
- package/src/jsonRpc/core.ts +19 -6
- package/src/version.ts +1 -1
- package/docs/clients/json-rpc.md +0 -243
|
@@ -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,19 +1,10 @@
|
|
|
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
|
-
Use `SuiGraphQLClient` when an app needs indexed GraphQL data, historical queries, or custom
|
|
11
|
-
selection sets that are not exposed by the gRPC top-level API.
|
|
12
|
-
|
|
13
|
-
## Using top-level methods
|
|
14
|
-
|
|
15
|
-
`SuiGraphQLClient` exposes top-level methods for the same common operations as the
|
|
16
|
-
[Core API](/sui/clients/core). Use them directly in application code:
|
|
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:
|
|
17
8
|
|
|
18
9
|
```typescript
|
|
19
10
|
|
|
@@ -26,70 +17,45 @@ const { object } = await client.getObject({
|
|
|
26
17
|
objectId: '0x...',
|
|
27
18
|
include: { content: true },
|
|
28
19
|
});
|
|
29
|
-
|
|
30
|
-
const txs = await client.listTransactions({
|
|
31
|
-
filter: { sender: '0x...' },
|
|
32
|
-
order: 'descending',
|
|
33
|
-
limit: 10,
|
|
34
|
-
});
|
|
35
20
|
```
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Common top-level methods:
|
|
41
|
-
|
|
42
|
-
| Category | Methods |
|
|
43
|
-
| -------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
44
|
-
| Objects | `getObject`, `getObjects`, `listOwnedObjects`, `listDynamicFields`, `getDynamicField` |
|
|
45
|
-
| Coins | `listCoins`, `getBalance`, `listBalances`, `getCoinMetadata` |
|
|
46
|
-
| Transactions | `getTransaction`, `executeTransaction`, `signAndExecuteTransaction`, `waitForTransaction` |
|
|
47
|
-
| Simulation | `simulateTransaction` |
|
|
48
|
-
| Queries | `listTransactions`, `listEvents` |
|
|
49
|
-
| Move and names | `getMoveFunction`, `resolveNameServiceAddress`, `defaultNameServiceName`, `mvr.resolvePackage`, `mvr.resolveType` |
|
|
50
|
-
| Verification | `verifyZkLoginSignature` |
|
|
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.
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
`include: { value: true }` on `listDynamicFields`.
|
|
26
|
+
The constructor takes:
|
|
54
27
|
|
|
55
|
-
|
|
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 |
|
|
56
36
|
|
|
57
|
-
|
|
58
|
-
queries.
|
|
37
|
+
## Writing queries
|
|
59
38
|
|
|
60
|
-
|
|
39
|
+
Use `query` to run any GraphQL document against the endpoint:
|
|
61
40
|
|
|
62
41
|
```typescript
|
|
63
42
|
|
|
64
|
-
const gqlClient = new SuiGraphQLClient({
|
|
65
|
-
url: 'https://graphql.testnet.sui.io/graphql',
|
|
66
|
-
network: 'testnet',
|
|
67
|
-
});
|
|
68
|
-
|
|
69
43
|
const chainIdentifierQuery = graphql(`
|
|
70
44
|
query {
|
|
71
45
|
chainIdentifier
|
|
72
46
|
}
|
|
73
47
|
`);
|
|
74
48
|
|
|
75
|
-
|
|
76
|
-
const result = await gqlClient.query({
|
|
77
|
-
query: chainIdentifierQuery,
|
|
78
|
-
});
|
|
49
|
+
const result = await client.query({ query: chainIdentifierQuery });
|
|
79
50
|
|
|
80
|
-
|
|
81
|
-
}
|
|
51
|
+
console.log(result.data?.chainIdentifier);
|
|
82
52
|
```
|
|
83
53
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
You might have noticed the example above does not include any type definitions for the query. The
|
|
87
|
-
`graphql` function used in the example is powered by [`gql.tada`](https://gql-tada.0no.co/) and will
|
|
88
|
-
automatically provide the required type information to ensure that your queries are properly typed
|
|
89
|
-
when executed through `SuiGraphQLClient`.
|
|
54
|
+
### Type safety
|
|
90
55
|
|
|
91
|
-
The `graphql` function
|
|
92
|
-
|
|
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:
|
|
93
59
|
|
|
94
60
|
```typescript
|
|
95
61
|
const getSuinsName = graphql(`
|
|
@@ -103,24 +69,22 @@ const getSuinsName = graphql(`
|
|
|
103
69
|
`);
|
|
104
70
|
|
|
105
71
|
async function getDefaultSuinsName(address: string) {
|
|
106
|
-
const result = await
|
|
72
|
+
const result = await client.query({
|
|
107
73
|
query: getSuinsName,
|
|
108
|
-
variables: {
|
|
109
|
-
address,
|
|
110
|
-
},
|
|
74
|
+
variables: { address },
|
|
111
75
|
});
|
|
112
76
|
|
|
113
77
|
return result.data?.address?.defaultNameRecord?.domain;
|
|
114
78
|
}
|
|
115
79
|
```
|
|
116
80
|
|
|
117
|
-
|
|
81
|
+
### Using typed documents with other clients
|
|
118
82
|
|
|
119
|
-
The `graphql` function returns document nodes
|
|
120
|
-
[`TypedDocumentNode`](https://github.com/dotansimha/graphql-typed-document-node) standard,
|
|
121
|
-
|
|
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:
|
|
122
86
|
|
|
123
|
-
```
|
|
87
|
+
```tsx
|
|
124
88
|
|
|
125
89
|
const chainIdentifierQuery = graphql(`
|
|
126
90
|
query {
|
|
@@ -129,8 +93,54 @@ const chainIdentifierQuery = graphql(`
|
|
|
129
93
|
`);
|
|
130
94
|
|
|
131
95
|
function ChainIdentifier() {
|
|
132
|
-
|
|
96
|
+
// Result types flow through the other client's own hooks and methods
|
|
97
|
+
const { data } = useQuery(chainIdentifierQuery);
|
|
133
98
|
|
|
134
|
-
return <
|
|
99
|
+
return <span>{data?.chainIdentifier}</span>;
|
|
135
100
|
}
|
|
136
|
-
```
|
|
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.
|