@mysten/sui 2.17.0 → 2.18.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 +18 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- 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/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/transactions/Transaction.d.mts +16 -2
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +8 -3
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/index.d.mts +2 -2
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/jwt-utils.d.mts.map +1 -1
- package/dist/zklogin/jwt-utils.mjs.map +1 -1
- package/dist/zklogin/utils.d.mts.map +1 -1
- package/dist/zklogin/utils.mjs +9 -0
- package/dist/zklogin/utils.mjs.map +1 -1
- package/docs/bcs.md +11 -6
- package/docs/clients/core.md +10 -9
- package/docs/clients/grpc.md +1 -1
- package/docs/index.md +176 -22
- package/docs/llms-index.md +6 -9
- package/docs/migrations/0.38.md +2 -2
- package/docs/migrations/sui-1.0.md +2 -2
- package/docs/migrations/sui-2.0/json-rpc-migration.md +76 -33
- package/docs/plugins.md +29 -5
- package/docs/transactions/basics.md +279 -0
- package/docs/transactions/coins-and-balances.md +293 -0
- package/docs/transactions/offline.md +192 -0
- package/docs/transactions/reference.md +380 -0
- package/docs/transactions/signing-and-execution.md +401 -0
- package/package.json +26 -26
- package/src/transactions/Transaction.ts +36 -5
- package/src/transactions/index.ts +1 -0
- package/src/version.ts +1 -1
- package/src/zklogin/jwt-utils.ts +3 -0
- package/src/zklogin/utils.ts +17 -0
- package/docs/faucet.md +0 -26
- package/docs/hello-sui.md +0 -115
- package/docs/install.md +0 -61
- package/docs/transaction-building/basics.md +0 -299
- package/docs/transaction-building/gas.md +0 -61
- package/docs/transaction-building/intents.md +0 -62
- package/docs/transaction-building/offline.md +0 -73
- package/docs/transaction-building/sponsored-transactions.md +0 -22
package/docs/clients/core.md
CHANGED
|
@@ -178,13 +178,14 @@ The `display` field is `null` when the object's type has no registered Display t
|
|
|
178
178
|
Get the balance of a specific coin type for an owner.
|
|
179
179
|
|
|
180
180
|
```typescript
|
|
181
|
-
const balance = await client.core.getBalance({
|
|
181
|
+
const { balance } = await client.core.getBalance({
|
|
182
182
|
owner: '0xabc...',
|
|
183
183
|
coinType: '0x2::sui::SUI', // Optional, defaults to SUI
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
-
console.log(balance.
|
|
187
|
-
console.log(balance.
|
|
186
|
+
console.log(balance.balance); // Total balance (coin objects + address balance)
|
|
187
|
+
console.log(balance.coinBalance); // Balance from coin objects only
|
|
188
|
+
console.log(balance.addressBalance); // Balance from address balance only
|
|
188
189
|
```
|
|
189
190
|
|
|
190
191
|
### `listBalances`
|
|
@@ -197,7 +198,7 @@ const { balances } = await client.core.listBalances({
|
|
|
197
198
|
});
|
|
198
199
|
|
|
199
200
|
for (const balance of balances) {
|
|
200
|
-
console.log(balance.coinType, balance.
|
|
201
|
+
console.log(balance.coinType, balance.balance);
|
|
201
202
|
}
|
|
202
203
|
```
|
|
203
204
|
|
|
@@ -212,7 +213,7 @@ const result = await client.core.listCoins({
|
|
|
212
213
|
limit: 10,
|
|
213
214
|
});
|
|
214
215
|
|
|
215
|
-
for (const coin of result.
|
|
216
|
+
for (const coin of result.objects) {
|
|
216
217
|
console.log(coin.objectId, coin.balance);
|
|
217
218
|
}
|
|
218
219
|
```
|
|
@@ -454,7 +455,7 @@ console.log(referenceGasPrice); // bigint
|
|
|
454
455
|
Get the current system state including epoch information.
|
|
455
456
|
|
|
456
457
|
```typescript
|
|
457
|
-
const systemState = await client.core.getCurrentSystemState();
|
|
458
|
+
const { systemState } = await client.core.getCurrentSystemState();
|
|
458
459
|
console.log(systemState.epoch);
|
|
459
460
|
console.log(systemState.systemStateVersion);
|
|
460
461
|
```
|
|
@@ -478,7 +479,7 @@ Get information about a Move function.
|
|
|
478
479
|
const { function: fn } = await client.core.getMoveFunction({
|
|
479
480
|
packageId: '0x2',
|
|
480
481
|
moduleName: 'coin',
|
|
481
|
-
name: '
|
|
482
|
+
name: 'value',
|
|
482
483
|
});
|
|
483
484
|
|
|
484
485
|
console.log(fn.name);
|
|
@@ -566,7 +567,7 @@ function processObject(obj: SuiClientTypes.Object<{ content: true }>) {
|
|
|
566
567
|
async function fetchBalance(
|
|
567
568
|
client: ClientWithCoreApi,
|
|
568
569
|
owner: string,
|
|
569
|
-
): Promise<SuiClientTypes.
|
|
570
|
+
): Promise<SuiClientTypes.Balance> {
|
|
570
571
|
const { balance } = await client.core.getBalance({ owner });
|
|
571
572
|
return balance;
|
|
572
573
|
}
|
|
@@ -584,7 +585,7 @@ const options: SuiClientTypes.GetObjectOptions<{ content: true }> = {
|
|
|
584
585
|
| ---------------------- | ------------------------------------------- |
|
|
585
586
|
| `Object<Include>` | Fetched object with optional included data |
|
|
586
587
|
| `Coin` | Coin object with balance |
|
|
587
|
-
| `
|
|
588
|
+
| `Balance` | Balance summary for a coin type |
|
|
588
589
|
| `CoinMetadata` | Metadata for a coin type |
|
|
589
590
|
| `Transaction<Include>` | Executed transaction with optional data |
|
|
590
591
|
| `TransactionResult` | Success or failure result from execution |
|
package/docs/clients/grpc.md
CHANGED
|
@@ -179,7 +179,7 @@ const { response: fields } = await grpcClient.stateService.listDynamicFields({
|
|
|
179
179
|
const { response } = await grpcClient.movePackageService.getFunction({
|
|
180
180
|
packageId: '0x2',
|
|
181
181
|
moduleName: 'coin',
|
|
182
|
-
name: '
|
|
182
|
+
name: 'value',
|
|
183
183
|
});
|
|
184
184
|
```
|
|
185
185
|
|
package/docs/index.md
CHANGED
|
@@ -1,22 +1,55 @@
|
|
|
1
|
-
# Sui TypeScript SDK
|
|
1
|
+
# Sui TypeScript SDK
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> TypeScript SDK for building on the Sui blockchain
|
|
4
4
|
|
|
5
5
|
The Sui TypeScript SDK is a modular library of tools for interacting with the Sui blockchain. Use it
|
|
6
6
|
to send queries to RPC nodes, build and sign transactions, and interact with a Sui or local network.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
|
-
```
|
|
10
|
+
```npm
|
|
11
11
|
npm i @mysten/sui
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
The SDK is published as an ESM only package. Make sure your `package.json` includes
|
|
15
|
+
`"type": "module"`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"type": "module"
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
If you are using TypeScript, your `tsconfig.json` should use a compatible `moduleResolution` setting
|
|
24
|
+
such as `"NodeNext"`, `"Node16"`, or `"Bundler"`.
|
|
25
|
+
|
|
26
|
+
## Module packages
|
|
27
|
+
|
|
28
|
+
The SDK contains a set of modular packages that you can use independently or together. Import just
|
|
29
|
+
what you need to keep your code light and compact.
|
|
30
|
+
|
|
31
|
+
- [`@mysten/sui/client`](/sui/clients): A client for interacting with Sui RPC nodes.
|
|
32
|
+
- [`@mysten/sui/bcs`](/sui/bcs): A BCS builder with pre-defined types for Sui.
|
|
33
|
+
- [`@mysten/sui/transactions`](/sui/transactions/basics): Utilities for building and interacting
|
|
34
|
+
with transactions.
|
|
35
|
+
- [`@mysten/sui/keypairs/*`](/sui/cryptography/keypairs): Modular exports for specific KeyPair
|
|
36
|
+
implementations.
|
|
37
|
+
- [`@mysten/sui/verify`](/sui/cryptography/keypairs#verifying-signatures-without-a-key-pair):
|
|
38
|
+
Methods for verifying transactions and messages.
|
|
39
|
+
- [`@mysten/sui/cryptography`](/sui/cryptography/keypairs): Shared types and classes for
|
|
40
|
+
cryptography.
|
|
41
|
+
- [`@mysten/sui/multisig`](/sui/cryptography/multisig): Utilities for working with multisig
|
|
42
|
+
signatures.
|
|
43
|
+
- [`@mysten/sui/utils`](/sui/utils): Utilities for formatting and parsing various Sui types.
|
|
44
|
+
- [`@mysten/sui/faucet`](#faucet): Methods for requesting SUI from a faucet.
|
|
45
|
+
- [`@mysten/sui/zklogin`](/sui/zklogin): Utilities for working with zkLogin.
|
|
46
|
+
|
|
14
47
|
## Network locations
|
|
15
48
|
|
|
16
49
|
The following table lists the locations for Sui networks.
|
|
17
50
|
|
|
18
51
|
| Network | Full node | faucet |
|
|
19
|
-
|
|
|
52
|
+
| ------- | ------------------------------------- | ---------------------------------------- |
|
|
20
53
|
| local | `http://127.0.0.1:9000` (default) | `http://127.0.0.1:9123/v2/gas` (default) |
|
|
21
54
|
| Devnet | `https://fullnode.devnet.sui.io:443` | `https://faucet.devnet.sui.io/v2/gas` |
|
|
22
55
|
| Testnet | `https://fullnode.testnet.sui.io:443` | `https://faucet.testnet.sui.io/v2/gas` |
|
|
@@ -31,23 +64,144 @@ The following table lists the locations for Sui networks.
|
|
|
31
64
|
> (preferred for apps that have high traffic). You can find a list of reliable RPC endpoint providers
|
|
32
65
|
> for Sui on the [Sui Dev Portal](https://sui.io/developers#dev-tools) using the **Node Service** tab.
|
|
33
66
|
|
|
34
|
-
##
|
|
67
|
+
## Quick start
|
|
35
68
|
|
|
36
|
-
|
|
37
|
-
|
|
69
|
+
Get started in a few minutes. This guide walks you through creating a keypair, funding it from a
|
|
70
|
+
faucet, and checking your balance.
|
|
38
71
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
72
|
+
### Create a project
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
mkdir hello-sui
|
|
76
|
+
cd hello-sui
|
|
77
|
+
npm init -y
|
|
78
|
+
npm pkg set type=module
|
|
79
|
+
npm i @mysten/sui
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Step 1: Create a keypair and get SUI
|
|
83
|
+
|
|
84
|
+
Create a `setup.ts` file that generates a new keypair, requests SUI from the faucet, and prints your
|
|
85
|
+
secret key for later use:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
|
|
89
|
+
// Generate a new keypair
|
|
90
|
+
const keypair = new Ed25519Keypair();
|
|
91
|
+
|
|
92
|
+
console.log('Address:', keypair.toSuiAddress());
|
|
93
|
+
console.log('Secret key:', keypair.getSecretKey());
|
|
94
|
+
|
|
95
|
+
// Request SUI from the devnet faucet
|
|
96
|
+
await requestSuiFromFaucetV2({
|
|
97
|
+
host: getFaucetHost('devnet'),
|
|
98
|
+
recipient: keypair.toSuiAddress(),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log('Faucet request sent! Save the secret key above for the next step.');
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Run it:
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
node setup.ts
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Save the secret key that gets printed; you'll use it in the next step.
|
|
111
|
+
|
|
112
|
+
> **Warning:** Logging secret keys to the console is only appropriate for quick demos like this. In real
|
|
113
|
+
> applications, never log or expose secret keys. Store them securely using environment variables,
|
|
114
|
+
> encrypted keystores, or a secrets manager.
|
|
115
|
+
|
|
116
|
+
### Step 2: Check your balance
|
|
117
|
+
|
|
118
|
+
Create a `balance.ts` file that imports your keypair from the secret key and checks the balance:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
|
|
122
|
+
// Import the keypair using the secret key from step 1
|
|
123
|
+
const keypair = Ed25519Keypair.fromSecretKey('suiprivkey1...'); // paste your secret key here
|
|
124
|
+
|
|
125
|
+
const grpcClient = new SuiGrpcClient({
|
|
126
|
+
network: 'devnet',
|
|
127
|
+
baseUrl: 'https://fullnode.devnet.sui.io:443',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const { balance } = await grpcClient.core.getBalance({
|
|
131
|
+
owner: keypair.toSuiAddress(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const sui = Number(balance.balance) / Number(MIST_PER_SUI);
|
|
135
|
+
console.log(`Address: ${keypair.toSuiAddress()}`);
|
|
136
|
+
console.log(`Balance: ${sui} SUI`);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Run it:
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
node balance.ts
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Step 3: Transfer SUI
|
|
146
|
+
|
|
147
|
+
Create a `transfer.ts` file that sends SUI to another address and logs the transaction effects:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
|
|
151
|
+
const keypair = Ed25519Keypair.fromSecretKey('suiprivkey1...'); // paste your secret key here
|
|
152
|
+
const grpcClient = new SuiGrpcClient({
|
|
153
|
+
network: 'devnet',
|
|
154
|
+
baseUrl: 'https://fullnode.devnet.sui.io:443',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const tx = new Transaction();
|
|
158
|
+
|
|
159
|
+
tx.transferObjects(
|
|
160
|
+
[coinWithBalance({ balance: BigInt(0.1 * Number(MIST_PER_SUI)) })],
|
|
161
|
+
'0xRecipientAddress', // replace with the recipient's address
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const result = await keypair.signAndExecuteTransaction({
|
|
165
|
+
transaction: tx,
|
|
166
|
+
client: grpcClient,
|
|
167
|
+
include: { effects: true, balanceChanges: true },
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (result.$kind === 'FailedTransaction') {
|
|
171
|
+
console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
|
|
172
|
+
} else {
|
|
173
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
174
|
+
console.log('Effects:', JSON.stringify(result.Transaction.effects, null, 2));
|
|
175
|
+
console.log('Balance changes:', JSON.stringify(result.Transaction.balanceChanges, null, 2));
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Run it:
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
node transfer.ts
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Faucet
|
|
186
|
+
|
|
187
|
+
Devnet, Testnet, and local networks include faucets that mint SUI. Use `requestSuiFromFaucetV2` to
|
|
188
|
+
request SUI programmatically:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
|
|
192
|
+
await requestSuiFromFaucetV2({
|
|
193
|
+
host: getFaucetHost('testnet'),
|
|
194
|
+
recipient: '0xYourAddress',
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
> **Note:** Faucets on Devnet and Testnet are rate limited. If you hit the limit, wait before trying again.
|
|
199
|
+
> For Testnet, you can also get SUI through the web UI at `faucet.sui.io` or through the [Sui
|
|
200
|
+
> Discord](https://discord.gg/sui) faucet channels.
|
|
201
|
+
|
|
202
|
+
## Next steps
|
|
203
|
+
|
|
204
|
+
- [Building Transactions](/sui/transactions/basics): create and compose transactions
|
|
205
|
+
- [Signing and Execution](/sui/transactions/signing-and-execution): sign and submit transactions
|
|
206
|
+
- [Coins and Balances](/sui/transactions/coins-and-balances): work with tokens
|
|
207
|
+
- [Client Setup](/sui/clients): configure clients for different networks
|
package/docs/llms-index.md
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
# Sui SDK
|
|
2
2
|
> TypeScript interfaces for Sui
|
|
3
3
|
|
|
4
|
-
- [Sui TypeScript SDK
|
|
5
|
-
- [Install Sui TypeScript SDK](./install.md): Install the @mysten/sui package and configure your project.
|
|
4
|
+
- [Sui TypeScript SDK](..md): TypeScript SDK for building on the Sui blockchain
|
|
6
5
|
- [LLM Documentation](./llm-docs.md): Give AI agents access to Sui SDK documentation in your project.
|
|
7
|
-
- [Hello Sui](./hello-sui.md): Build your first Sui application with the TypeScript SDK.
|
|
8
|
-
- [Faucet](./faucet.md): Request test SUI tokens from the faucet on Devnet, Testnet, or local networks.
|
|
9
6
|
- [Sui Clients](./clients.md): Choose and configure gRPC, GraphQL, or JSON-RPC clients for the Sui network.
|
|
10
7
|
- [Core API](./clients/core.md): Transport-agnostic Core API shared by all Sui clients.
|
|
11
8
|
- [SuiGrpcClient](./clients/grpc.md): Connect to Sui through gRPC with SuiGrpcClient.
|
|
12
9
|
- [SuiGraphQLClient](./clients/graphql.md): Connect to Sui through GraphQL with SuiGraphQLClient.
|
|
13
10
|
- [SuiJsonRpcClient](./clients/json-rpc.md): Connect to Sui through JSON-RPC with SuiJsonRpcClient.
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
11
|
+
- [Building Transactions](./transactions/basics.md): Construct programmable transaction blocks with the Transaction API
|
|
12
|
+
- [Signing and Execution](./transactions/signing-and-execution.md): Sign transactions and execute them on the Sui network
|
|
13
|
+
- [Coins and Balances](./transactions/coins-and-balances.md): Work with coin objects and address balances in transactions
|
|
14
|
+
- [Commands and Inputs Reference](./transactions/reference.md): Complete reference for transaction commands and input types
|
|
15
|
+
- [Building Offline](./transactions/offline.md): Build transactions without a network connection
|
|
19
16
|
- [Key pairs](./cryptography/keypairs.md): Create and manage Ed25519, Secp256k1, and Secp256r1 keypairs for Sui transaction signing.
|
|
20
17
|
- [Multi-Signature Transactions](./cryptography/multisig.md): Create multi-signature transactions with multiple signers on Sui.
|
|
21
18
|
- [Passkey](./cryptography/passkey.md): Use WebAuthn passkeys for Sui transaction signing.
|
package/docs/migrations/0.38.md
CHANGED
|
@@ -13,7 +13,7 @@ earlier version of the SDK, there are some changes you should consider when upda
|
|
|
13
13
|
|
|
14
14
|
The Sui TypeScript SDK is now divided into modular components. Before version 0.38.0, you imported
|
|
15
15
|
the complete SDK module. Now, you upload the individual packages of the SDK module instead. See the
|
|
16
|
-
[Module
|
|
16
|
+
[Module Structure section](#module-structure) for the list of packages.
|
|
17
17
|
|
|
18
18
|
### Deprecated classes
|
|
19
19
|
|
|
@@ -40,7 +40,7 @@ The Sui TypeScript SDK deprecates the following classes with version 0.38.0:
|
|
|
40
40
|
|
|
41
41
|
Signing and sending transactions changes slightly with the deprecation of the `Signer` pattern. For
|
|
42
42
|
an example of transaction signing, see the
|
|
43
|
-
[Sui Programmable Transaction
|
|
43
|
+
[Sui Programmable Transaction Block Basics](/sui/transactions/basics) topic.
|
|
44
44
|
|
|
45
45
|
### Faucet requests
|
|
46
46
|
|
|
@@ -11,7 +11,7 @@ highlights:
|
|
|
11
11
|
|
|
12
12
|
- [A new GraphQL Client for the newly released Sui GraphQL API](/sui/clients/graphql)
|
|
13
13
|
- [New Transaction Executor classes for efficient Transaction execution](../executors)
|
|
14
|
-
- [New Transaction Intents to simplify common transaction patterns](../
|
|
14
|
+
- [New Transaction Intents to simplify common transaction patterns](../transactions/coins-and-balances)
|
|
15
15
|
- [A new Plugin system for Extending Transaction Building](../plugins)
|
|
16
16
|
|
|
17
17
|
The majority of changes in this release are in the `@mysten/sui` package, but the changes to API
|
|
@@ -24,7 +24,7 @@ As part of the 1.0 release the `@mysten/sui.js` package has been renamed to `@my
|
|
|
24
24
|
|
|
25
25
|
To upgrade to the new version, uninstall the old package and install the new one:
|
|
26
26
|
|
|
27
|
-
```
|
|
27
|
+
```npm
|
|
28
28
|
npm uninstall @mysten/sui.js
|
|
29
29
|
npm install @mysten/sui
|
|
30
30
|
```
|
|
@@ -92,22 +92,26 @@ These JSON-RPC methods have direct replacements in the core API:
|
|
|
92
92
|
|
|
93
93
|
These JSON-RPC methods can be replaced by calling gRPC service clients directly:
|
|
94
94
|
|
|
95
|
-
| JSON-RPC Method | gRPC Service Replacement
|
|
96
|
-
| ----------------------------------- |
|
|
97
|
-
| `getCheckpoint` | `ledgerService.getCheckpoint`
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
-
|
|
95
|
+
| JSON-RPC Method | gRPC Service Replacement |
|
|
96
|
+
| ----------------------------------- | ---------------------------------------------------------------- |
|
|
97
|
+
| `getCheckpoint` | `ledgerService.getCheckpoint` |
|
|
98
|
+
| `getLatestCheckpointSequenceNumber` | `ledgerService.getServiceInfo` (read `checkpointHeight`) |
|
|
99
|
+
| `getCurrentEpoch` | `ledgerService.getEpoch` (omit `epoch` for the current) |
|
|
100
|
+
| `getLatestSuiSystemState` | `ledgerService.getEpoch` with `system_state` in the read mask |
|
|
101
|
+
| `getCommitteeInfo` | `ledgerService.getEpoch` with `committee` in the read mask |
|
|
102
|
+
| `getProtocolConfig` | `ledgerService.getEpoch` with `protocol_config` in the read mask |
|
|
103
|
+
| `getCoinMetadata` | `stateService.getCoinInfo` (response includes `metadata`) |
|
|
104
|
+
| `getTotalSupply` | `stateService.getCoinInfo` (response includes `treasury`) |
|
|
105
|
+
| `getNormalizedMoveModule` | `movePackageService.getPackage` (response includes all modules) |
|
|
106
|
+
| `getNormalizedMoveModulesByPackage` | `movePackageService.getPackage` |
|
|
107
|
+
| `getNormalizedMoveStruct` | `movePackageService.getDatatype` |
|
|
108
|
+
| `resolveNameServiceAddress` | `nameService.lookupName` |
|
|
109
|
+
| `resolveNameServiceNames` | `nameService.reverseLookupName` |
|
|
110
|
+
|
|
111
|
+
> **Warning:** `getCheckpoints` and `getEpochs` (paginated listings) have no gRPC equivalent — use the
|
|
112
|
+
> `checkpoints` / `epochs` GraphQL queries instead. `getValidatorsApy` also has no replacement:
|
|
113
|
+
> there is no canonical definition of validator APY, so it must be computed client-side from
|
|
114
|
+
> validator exchange rates (see [Validator APY](#validator-apy) below).
|
|
111
115
|
|
|
112
116
|
### Example: using gRPC service clients
|
|
113
117
|
|
|
@@ -118,13 +122,32 @@ const client = new SuiGrpcClient({
|
|
|
118
122
|
network: 'mainnet',
|
|
119
123
|
});
|
|
120
124
|
|
|
121
|
-
// Get checkpoint
|
|
125
|
+
// Get the latest checkpoint sequence number (replaces getLatestCheckpointSequenceNumber)
|
|
126
|
+
const { response: info } = await client.ledgerService.getServiceInfo({});
|
|
127
|
+
const latestCheckpoint = info.checkpointHeight;
|
|
128
|
+
|
|
129
|
+
// Get a specific checkpoint by sequence number. `checkpointId` is required (a oneof);
|
|
130
|
+
// the read mask defaults to `sequence_number,digest`, so request more fields as needed.
|
|
122
131
|
const { response } = await client.ledgerService.getCheckpoint({
|
|
123
|
-
sequenceNumber:
|
|
132
|
+
checkpointId: { oneofKind: 'sequenceNumber', sequenceNumber: latestCheckpoint },
|
|
124
133
|
});
|
|
125
134
|
|
|
126
|
-
// Get current epoch
|
|
127
|
-
|
|
135
|
+
// Get the current epoch (omit `epoch` for the current one). The system state,
|
|
136
|
+
// committee, and protocol config are NOT returned by default — you must request
|
|
137
|
+
// them via the read mask (the default mask is just `epoch`).
|
|
138
|
+
const { response: epoch } = await client.ledgerService.getEpoch({
|
|
139
|
+
readMask: { paths: ['epoch', 'system_state', 'committee', 'protocol_config'] },
|
|
140
|
+
});
|
|
141
|
+
const systemState = epoch.epoch?.systemState;
|
|
142
|
+
const committee = epoch.epoch?.committee;
|
|
143
|
+
const protocolConfig = epoch.epoch?.protocolConfig;
|
|
144
|
+
|
|
145
|
+
// Get coin metadata and total supply in one call
|
|
146
|
+
const { response: coinInfo } = await client.stateService.getCoinInfo({
|
|
147
|
+
coinType: '0x2::sui::SUI',
|
|
148
|
+
});
|
|
149
|
+
const metadata = coinInfo.metadata;
|
|
150
|
+
const totalSupply = coinInfo.treasury?.totalSupply;
|
|
128
151
|
|
|
129
152
|
// Get Move package information (includes all modules)
|
|
130
153
|
const { response: pkg } = await client.movePackageService.getPackage({
|
|
@@ -148,19 +171,21 @@ const { response: address } = await client.nameService.lookupName({
|
|
|
148
171
|
|
|
149
172
|
Some JSON-RPC methods don't have gRPC equivalents and require using `SuiGraphQLClient` instead:
|
|
150
173
|
|
|
151
|
-
| JSON-RPC Method | GraphQL Alternative
|
|
152
|
-
| --------------------------- |
|
|
153
|
-
| `queryTransactionBlocks` | `transactions` query
|
|
154
|
-
| `multiGetTransactionBlocks` | `multiGetTransactionEffects` query
|
|
155
|
-
| `queryEvents` | `events` query
|
|
156
|
-
| `
|
|
157
|
-
| `
|
|
158
|
-
| `
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
174
|
+
| JSON-RPC Method | GraphQL Alternative |
|
|
175
|
+
| --------------------------- | --------------------------------------------------------- |
|
|
176
|
+
| `queryTransactionBlocks` | `transactions` query |
|
|
177
|
+
| `multiGetTransactionBlocks` | `multiGetTransactionEffects` query |
|
|
178
|
+
| `queryEvents` | `events` query |
|
|
179
|
+
| `getCheckpoints` | `checkpoints` query |
|
|
180
|
+
| `getEpochs` | `epochs` query |
|
|
181
|
+
| `getCoinMetadata` | `coinMetadata` query (or gRPC `stateService.getCoinInfo`) |
|
|
182
|
+
| `getTotalSupply` | `coinMetadata` query (or gRPC `stateService.getCoinInfo`) |
|
|
183
|
+
| `getStakes` | `address.stakedSuis` query |
|
|
184
|
+
| `getStakesByIds` | `multiGetObjects` query |
|
|
185
|
+
| `tryGetPastObject` | Historical object queries |
|
|
186
|
+
| `getNetworkMetrics` | Use indexer |
|
|
187
|
+
| `getAddressMetrics` | Use indexer |
|
|
188
|
+
| `getMoveCallMetrics` | Use indexer |
|
|
164
189
|
|
|
165
190
|
### Setting up GraphQL client
|
|
166
191
|
|
|
@@ -364,6 +389,24 @@ const result = await graphqlClient.query({
|
|
|
364
389
|
});
|
|
365
390
|
```
|
|
366
391
|
|
|
392
|
+
## Validator APY
|
|
393
|
+
|
|
394
|
+
There is **no replacement** for `getValidatorsApy`, and one will not be added. There is no canonical
|
|
395
|
+
definition of validator APY — no other chain's core/general-purpose RPCs offer this endpoint — so it
|
|
396
|
+
must be computed client-side from validator staking-pool exchange rates.
|
|
397
|
+
|
|
398
|
+
The general approach: read each validator's `exchangeRates` (a table of `pool_token_amount` /
|
|
399
|
+
`sui_amount` per epoch) and estimate the annualized rate from the change in exchange rate over the
|
|
400
|
+
trailing epochs. Two concrete reference implementations:
|
|
401
|
+
|
|
402
|
+
- The `jsonrpc-alt` implementation in
|
|
403
|
+
[`sui-indexer-alt-jsonrpc`](https://github.com/MystenLabs/sui/blob/31537d4d9235b9f61dc07a3a71b05ed61a2bda7b/crates/sui-indexer-alt-jsonrpc/src/api/governance.rs#L422-L440),
|
|
404
|
+
which is compact and readable.
|
|
405
|
+
- [This GraphQL approach](https://github.com/MystenLabs/sui/issues/23832#issuecomment-4437791087),
|
|
406
|
+
which fetches the precursor exchange-rate information in a single query.
|
|
407
|
+
|
|
408
|
+
Treat whichever formula you adopt as _a_ definition of validator APY, not _the_ definition.
|
|
409
|
+
|
|
367
410
|
## Response format differences
|
|
368
411
|
|
|
369
412
|
The gRPC client uses the core API response format, which differs from JSON-RPC responses. See the
|
package/docs/plugins.md
CHANGED
|
@@ -148,7 +148,7 @@ Adding an intent is similar to adding any other command to a transaction:
|
|
|
148
148
|
const transaction = new Transaction();
|
|
149
149
|
|
|
150
150
|
transaction.add(
|
|
151
|
-
|
|
151
|
+
TransactionCommands.Intent({
|
|
152
152
|
name: 'TransferToSender',
|
|
153
153
|
inputs: {
|
|
154
154
|
objects: [transaction.object(someId)],
|
|
@@ -166,7 +166,7 @@ current transaction instance. This allows us to create a helper that automatical
|
|
|
166
166
|
function transferToSender(objects: TransactionObjectInput[]) {
|
|
167
167
|
return (tx: Transaction) => {
|
|
168
168
|
tx.add(
|
|
169
|
-
|
|
169
|
+
TransactionCommands.Intent({
|
|
170
170
|
name: 'TransferToSender',
|
|
171
171
|
inputs: {
|
|
172
172
|
objects: objects.map((obj) => tx.object(obj)),
|
|
@@ -214,7 +214,7 @@ async function resolveTransferToSender(
|
|
|
214
214
|
|
|
215
215
|
// This will replace the intent command with the correct TransferObjects command
|
|
216
216
|
transactionData.replaceCommand(index, [
|
|
217
|
-
|
|
217
|
+
TransactionCommands.TransferObjects(
|
|
218
218
|
// The inputs for intents are not currently typed, so we need to cast to the correct type here
|
|
219
219
|
transaction.$Intent.inputs.objects as Extract<
|
|
220
220
|
TransactionObjectArgument,
|
|
@@ -243,7 +243,7 @@ function transferToSender(objects: TransactionObjectInput[]) {
|
|
|
243
243
|
// As long as we are adding the same function reference, it will only be added once
|
|
244
244
|
tx.addIntentResolver('TransferToSender', resolveTransferToSender);
|
|
245
245
|
tx.add(
|
|
246
|
-
|
|
246
|
+
TransactionCommands.Intent({
|
|
247
247
|
name: 'TransferToSender',
|
|
248
248
|
inputs: {
|
|
249
249
|
objects: objects.map((obj) => tx.object(obj)),
|
|
@@ -255,4 +255,28 @@ function transferToSender(objects: TransactionObjectInput[]) {
|
|
|
255
255
|
|
|
256
256
|
const transaction = new Transaction();
|
|
257
257
|
transaction.add(transferToSender(['0x1234']));
|
|
258
|
-
```
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Copying transactions that use custom intents
|
|
261
|
+
|
|
262
|
+
`Transaction.from` creates a deep copy of a transaction. Copying is synchronous, so any unresolved
|
|
263
|
+
intents are carried over as-is and resolved later when the copy is built or serialized. To do that,
|
|
264
|
+
the copy needs the intent resolvers, but resolvers are functions and cannot be represented in the
|
|
265
|
+
serialized transaction data.
|
|
266
|
+
|
|
267
|
+
Built-in intents (such as the `CoinWithBalance` intent added by `tx.coin()`) are re-attached
|
|
268
|
+
automatically. For custom intents, pass the resolvers through the `intentResolvers` option so the
|
|
269
|
+
copy knows how to resolve them:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
|
|
273
|
+
const copy = Transaction.from(transaction, {
|
|
274
|
+
intentResolvers: {
|
|
275
|
+
TransferToSender: resolveTransferToSender,
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Without this, `Transaction.from` throws if the transaction still contains unresolved custom intents.
|
|
281
|
+
Alternatively, you can `await transaction.prepareForSerialization()` first to resolve the intents
|
|
282
|
+
before copying, but that requires an async call and (for some intents) a client.
|