@mysten/docs 0.1.1
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/README.md +24 -0
- package/dist/bcs/index.md +358 -0
- package/dist/bcs/llms-index.md +4 -0
- package/dist/codegen/index.md +441 -0
- package/dist/codegen/llms-index.md +4 -0
- package/dist/dapp-kit/actions/connect-wallet.md +69 -0
- package/dist/dapp-kit/actions/disconnect-wallet.md +38 -0
- package/dist/dapp-kit/actions/sign-and-execute-transaction.md +96 -0
- package/dist/dapp-kit/actions/sign-personal-message.md +58 -0
- package/dist/dapp-kit/actions/sign-transaction.md +65 -0
- package/dist/dapp-kit/actions/switch-account.md +37 -0
- package/dist/dapp-kit/actions/switch-network.md +37 -0
- package/dist/dapp-kit/dapp-kit-instance.md +162 -0
- package/dist/dapp-kit/getting-started/create-dapp.md +151 -0
- package/dist/dapp-kit/getting-started/next-js.md +162 -0
- package/dist/dapp-kit/getting-started/react.md +172 -0
- package/dist/dapp-kit/getting-started/vue.md +193 -0
- package/dist/dapp-kit/index.md +70 -0
- package/dist/dapp-kit/llms-index.md +26 -0
- package/dist/dapp-kit/react/components/connect-button.md +42 -0
- package/dist/dapp-kit/react/components/connect-modal.md +51 -0
- package/dist/dapp-kit/react/components/index.md +13 -0
- package/dist/dapp-kit/react/dapp-kit-provider.md +86 -0
- package/dist/dapp-kit/react/hooks/index.md +25 -0
- package/dist/dapp-kit/react/hooks/use-current-account.md +33 -0
- package/dist/dapp-kit/react/hooks/use-current-client.md +36 -0
- package/dist/dapp-kit/react/hooks/use-current-network.md +28 -0
- package/dist/dapp-kit/react/hooks/use-current-wallet.md +36 -0
- package/dist/dapp-kit/react/hooks/use-dapp-kit.md +100 -0
- package/dist/dapp-kit/react/hooks/use-wallet-connection.md +48 -0
- package/dist/dapp-kit/react/hooks/use-wallets.md +33 -0
- package/dist/dapp-kit/state.md +169 -0
- package/dist/dapp-kit/theming.md +196 -0
- package/dist/dapp-kit/web-components/connect-button.md +89 -0
- package/dist/dapp-kit/web-components/connect-modal.md +177 -0
- package/dist/kiosk/advanced-examples.md +101 -0
- package/dist/kiosk/from-v1.md +320 -0
- package/dist/kiosk/index.md +22 -0
- package/dist/kiosk/kiosk-client/introduction.md +52 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/examples.md +119 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/managing.md +235 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/purchasing.md +110 -0
- package/dist/kiosk/kiosk-client/querying.md +237 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
- package/dist/kiosk/llms-index.md +8 -0
- package/dist/llms-index.md +125 -0
- package/dist/payment-kit/getting-started.md +256 -0
- package/dist/payment-kit/index.md +132 -0
- package/dist/payment-kit/llms-index.md +8 -0
- package/dist/payment-kit/payment-kit-sdk.md +747 -0
- package/dist/payment-kit/payment-processing.md +372 -0
- package/dist/payment-kit/registry-management.md +529 -0
- package/dist/seal/index.md +85 -0
- package/dist/seal/llms-index.md +4 -0
- package/dist/slush-wallet/dapp.md +95 -0
- package/dist/slush-wallet/deep-linking.md +465 -0
- package/dist/slush-wallet/index.md +7 -0
- package/dist/slush-wallet/llms-index.md +6 -0
- package/dist/sui/bcs.md +134 -0
- package/dist/sui/clients/core.md +606 -0
- package/dist/sui/clients/graphql.md +101 -0
- package/dist/sui/clients/grpc.md +155 -0
- package/dist/sui/clients/index.md +95 -0
- package/dist/sui/clients/json-rpc.md +239 -0
- package/dist/sui/cryptography/keypairs.md +267 -0
- package/dist/sui/cryptography/multisig.md +194 -0
- package/dist/sui/cryptography/passkey.md +111 -0
- package/dist/sui/cryptography/webcrypto-signer.md +81 -0
- package/dist/sui/executors.md +148 -0
- package/dist/sui/faucet.md +26 -0
- package/dist/sui/hello-sui.md +115 -0
- package/dist/sui/index.md +53 -0
- package/dist/sui/install.md +61 -0
- package/dist/sui/llm-docs.md +32 -0
- package/dist/sui/llms-index.md +44 -0
- package/dist/sui/migrations/0.38.md +58 -0
- package/dist/sui/migrations/sui-1.0.md +455 -0
- package/dist/sui/migrations/sui-2.0/agent-prompt.md +42 -0
- package/dist/sui/migrations/sui-2.0/dapp-kit.md +350 -0
- package/dist/sui/migrations/sui-2.0/deepbook-v3.md +33 -0
- package/dist/sui/migrations/sui-2.0/index.md +158 -0
- package/dist/sui/migrations/sui-2.0/json-rpc-migration.md +386 -0
- package/dist/sui/migrations/sui-2.0/kiosk.md +120 -0
- package/dist/sui/migrations/sui-2.0/sdk-maintainers.md +90 -0
- package/dist/sui/migrations/sui-2.0/seal.md +14 -0
- package/dist/sui/migrations/sui-2.0/sui.md +341 -0
- package/dist/sui/migrations/sui-2.0/suins.md +43 -0
- package/dist/sui/migrations/sui-2.0/wallet-builders.md +66 -0
- package/dist/sui/migrations/sui-2.0/walrus.md +41 -0
- package/dist/sui/migrations/sui-2.0/zksend.md +95 -0
- package/dist/sui/plugins.md +258 -0
- package/dist/sui/sdk-building.md +344 -0
- package/dist/sui/transaction-building/basics.md +299 -0
- package/dist/sui/transaction-building/gas.md +62 -0
- package/dist/sui/transaction-building/intents.md +62 -0
- package/dist/sui/transaction-building/offline.md +73 -0
- package/dist/sui/transaction-building/sponsored-transactions.md +22 -0
- package/dist/sui/utils/derived_objects.md +59 -0
- package/dist/sui/utils/index.md +52 -0
- package/dist/sui/zklogin.md +83 -0
- package/dist/walrus/index.md +527 -0
- package/dist/walrus/llms-index.md +4 -0
- package/dist/zksend/index.md +27 -0
- package/dist/zksend/link-builder.md +192 -0
- package/dist/zksend/llms-index.md +5 -0
- package/package.json +66 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
# Sui TypeScript Codegen
|
|
2
|
+
|
|
3
|
+
> Generate type-safe TypeScript bindings from on-chain Sui Move packages
|
|
4
|
+
|
|
5
|
+
The `@mysten/codegen` package automatically generates type-safe TypeScript code from your Move
|
|
6
|
+
packages, enabling seamless interaction with your smart contracts from TypeScript applications.
|
|
7
|
+
|
|
8
|
+
> **Warning:** This package is currently in development and may have breaking changes.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Type-safe Move calls**: Generate TypeScript functions with full type safety for calling your
|
|
13
|
+
Move functions
|
|
14
|
+
- **BCS type definitions**: Automatic BCS struct definitions for parsing on-chain data
|
|
15
|
+
- **Auto-completion**: IDE support with intelligent code completion for Move function arguments
|
|
16
|
+
- **Package resolution**: Support for both MVR-registered packages and local packages
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install the codegen package as a dev dependency:
|
|
21
|
+
|
|
22
|
+
```sh npm2yarn
|
|
23
|
+
npm install -D @mysten/codegen
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Create a configuration file
|
|
29
|
+
|
|
30
|
+
Create a `sui-codegen.config.ts` file in your project root:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
|
|
34
|
+
const config: SuiCodegenConfig = {
|
|
35
|
+
output: './src/contracts',
|
|
36
|
+
packages: [
|
|
37
|
+
{
|
|
38
|
+
package: '@local-pkg/counter',
|
|
39
|
+
path: './move/counter',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Generate TypeScript code
|
|
47
|
+
|
|
48
|
+
Add a script to your `package.json`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"scripts": {
|
|
53
|
+
"codegen": "sui-ts-codegen generate"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Then run:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pnpm codegen
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This generates TypeScript code in your configured output directory (e.g., `./src/contracts`).
|
|
65
|
+
|
|
66
|
+
## Configuration Options
|
|
67
|
+
|
|
68
|
+
The `SuiCodegenConfig` type supports the following options:
|
|
69
|
+
|
|
70
|
+
| Option | Type | Default | Description |
|
|
71
|
+
| ------------------------------ | ---------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `output` | `string` | — | The directory where generated code will be written |
|
|
73
|
+
| `packages` | `PackageConfig[]` | — | Array of Move packages to generate code for |
|
|
74
|
+
| `prune` | `boolean` | `true` | When enabled, only generates code for the main package and omits dependency modules (dependency types referenced by included types are still generated under `deps/`) |
|
|
75
|
+
| `generateSummaries` | `boolean` | `true` | Automatically run `sui move summary` before generating code. Creates a `package_summaries` directory in your Move package which can be added to `.gitignore` |
|
|
76
|
+
| `generate` | `GenerateOptions` | — | Default [generate options](#the-generate-option) (types, functions) for all packages |
|
|
77
|
+
| `importExtension` | `'.js' \| '.ts' \| ''` | `'.js'` | File extension used in generated import statements |
|
|
78
|
+
| `includePhantomTypeParameters` | `boolean` | `false` | Include [phantom type parameters](#phantom-types) as function arguments in generated BCS types |
|
|
79
|
+
|
|
80
|
+
### Package Configuration
|
|
81
|
+
|
|
82
|
+
Each entry in the `packages` array configures a Move package to generate code from. Packages can be
|
|
83
|
+
local (from source) or on-chain (fetched from a network).
|
|
84
|
+
|
|
85
|
+
#### Local Packages
|
|
86
|
+
|
|
87
|
+
| Option | Type | Required | Description |
|
|
88
|
+
| ------------- | ------------------------ | -------- | -------------------------------------------------- |
|
|
89
|
+
| `package` | `string` | yes | Package identifier (e.g., `@local-pkg/my-package`) |
|
|
90
|
+
| `path` | `string` | yes | Path to the Move package directory |
|
|
91
|
+
| `packageName` | `string` | no | Custom name for generated code directory |
|
|
92
|
+
| `generate` | `PackageGenerateOptions` | no | Control what gets generated from this package |
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
{
|
|
96
|
+
package: '@local-pkg/my-package',
|
|
97
|
+
path: './move/my-package',
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### On-Chain Packages
|
|
102
|
+
|
|
103
|
+
For packages already deployed on-chain, generate code directly from a package ID or MVR name without
|
|
104
|
+
needing local source code:
|
|
105
|
+
|
|
106
|
+
| Option | Type | Required | Description |
|
|
107
|
+
| ------------- | ------------------------ | -------- | --------------------------------------------- |
|
|
108
|
+
| `package` | `string` | yes | Package ID or MVR name |
|
|
109
|
+
| `packageName` | `string` | yes | Name for the generated code directory |
|
|
110
|
+
| `network` | `'mainnet' \| 'testnet'` | yes | Network to fetch the package from |
|
|
111
|
+
| `generate` | `PackageGenerateOptions` | no | Control what gets generated from this package |
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
{
|
|
115
|
+
package: '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837',
|
|
116
|
+
packageName: 'pyth',
|
|
117
|
+
network: 'testnet',
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## The `generate` option
|
|
122
|
+
|
|
123
|
+
The `generate` option controls what code is produced. It can be set at the global level (as a
|
|
124
|
+
default for all packages), at the per-package level, and at the per-module level. More specific
|
|
125
|
+
settings override less specific ones.
|
|
126
|
+
|
|
127
|
+
When no `generate` option is set, everything is generated (all types and functions). Package-level
|
|
128
|
+
`types` and `functions` also default to `true`. In the record form of `modules`, per-module `types`
|
|
129
|
+
and `functions` default to `false` — you opt in to exactly what you need from each module. Use
|
|
130
|
+
`true` as a shorthand to include everything from a module with package-level defaults.
|
|
131
|
+
|
|
132
|
+
At the **global** and **package** levels, `types` and `functions` only accept boolean values (or an
|
|
133
|
+
object for `functions`). Name-based filtering with `string[]` is only available at the **module**
|
|
134
|
+
level inside the record form of `modules`, where the filter applies unambiguously to a single
|
|
135
|
+
module.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// Global or package level
|
|
139
|
+
generate: {
|
|
140
|
+
types: true | false,
|
|
141
|
+
functions: true | false | { private: boolean | 'entry' },
|
|
142
|
+
modules: string[] | Record<string, true | { types?, functions? }>, // package-level only
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Module level (inside the record form of modules)
|
|
146
|
+
modules: {
|
|
147
|
+
my_module: true, // shorthand for "include everything"
|
|
148
|
+
other_module: {
|
|
149
|
+
types: true | false | string[],
|
|
150
|
+
functions: true | false | string[] | { private: boolean | 'entry' },
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Types
|
|
156
|
+
|
|
157
|
+
Controls which BCS type definitions (structs and enums) are generated:
|
|
158
|
+
|
|
159
|
+
- `true` — generate all types
|
|
160
|
+
- `false` — skip type generation
|
|
161
|
+
- `string[]` — generate only the listed types by name _(module level only)_
|
|
162
|
+
|
|
163
|
+
### Functions
|
|
164
|
+
|
|
165
|
+
Controls which Move function wrappers are generated:
|
|
166
|
+
|
|
167
|
+
- `true` — generate all public functions and private entry functions
|
|
168
|
+
- `false` — skip function generation
|
|
169
|
+
- `string[]` — generate only the listed functions by name; includes private functions _(module level
|
|
170
|
+
only)_
|
|
171
|
+
- `{ private: 'entry' }` — generate public functions plus private entry functions
|
|
172
|
+
- `{ private: true }` — generate all functions including private
|
|
173
|
+
- `{ private: false }` — only generate public functions
|
|
174
|
+
|
|
175
|
+
### Modules
|
|
176
|
+
|
|
177
|
+
Controls which modules from the package are included. Only available at the package level, not at
|
|
178
|
+
the global level.
|
|
179
|
+
|
|
180
|
+
- Not set (default) — include all modules
|
|
181
|
+
- `string[]` — only include the listed modules
|
|
182
|
+
- `Record<string, true | { types?, functions? }>` — only include the listed modules, with per-module
|
|
183
|
+
overrides for `types` and `functions`. Use `true` as a shorthand to include everything from a
|
|
184
|
+
module with package-level defaults
|
|
185
|
+
|
|
186
|
+
### Examples
|
|
187
|
+
|
|
188
|
+
Only generate code from specific modules of the Sui framework:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
{
|
|
192
|
+
package: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
193
|
+
packageName: '0x2',
|
|
194
|
+
network: 'testnet',
|
|
195
|
+
generate: {
|
|
196
|
+
modules: ['kiosk', 'kiosk_extension', 'transfer_policy'],
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Only generate a single type from a dependency (functions are omitted automatically since `generate`
|
|
202
|
+
is configured and `functions` is not specified):
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
{
|
|
206
|
+
package: '0xabf837e98c26087cba0883c0a7a28326b1fa3c5e1e2c5abdb486f9e8f594c837',
|
|
207
|
+
packageName: 'pyth',
|
|
208
|
+
network: 'testnet',
|
|
209
|
+
generate: {
|
|
210
|
+
modules: {
|
|
211
|
+
state: { types: ['State'] },
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Generate specific types and functions from individual modules:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
{
|
|
221
|
+
package: '@local-pkg/my-package',
|
|
222
|
+
path: './move/my-package',
|
|
223
|
+
generate: {
|
|
224
|
+
modules: {
|
|
225
|
+
token: {
|
|
226
|
+
types: ['Token', 'TokenMetadata'],
|
|
227
|
+
functions: ['mint', 'burn', 'transfer'],
|
|
228
|
+
},
|
|
229
|
+
admin: {
|
|
230
|
+
types: true,
|
|
231
|
+
functions: ['initialize'],
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Generate all types but include all private functions for a local package:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
{
|
|
242
|
+
package: '@local-pkg/my-package',
|
|
243
|
+
path: './move/my-package',
|
|
244
|
+
generate: {
|
|
245
|
+
functions: { private: true },
|
|
246
|
+
},
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Dependency pruning
|
|
251
|
+
|
|
252
|
+
The global `prune` option (default: `true`) controls whether dependency packages are included in the
|
|
253
|
+
output. Even when pruning is enabled, dependency types referenced by your included types are still
|
|
254
|
+
generated under `deps/`:
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
src/contracts/
|
|
258
|
+
├── mypackage/
|
|
259
|
+
│ ├── module_a.ts
|
|
260
|
+
│ ├── module_b.ts
|
|
261
|
+
│ └── deps/
|
|
262
|
+
│ └── 0x2/
|
|
263
|
+
│ └── balance.ts # Auto-included dependency type
|
|
264
|
+
└── utils/
|
|
265
|
+
└── index.ts # Shared utilities (always generated)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Set `prune: false` to generate all dependency modules with their full types and functions.
|
|
269
|
+
|
|
270
|
+
## Phantom Types
|
|
271
|
+
|
|
272
|
+
In Move, phantom type parameters are type parameters that only appear at the type level and don't
|
|
273
|
+
affect the runtime data layout of a struct. For example, `Balance<T>` has a phantom type parameter
|
|
274
|
+
`T` that indicates the coin type, but the actual serialized data only contains a `u64` value:
|
|
275
|
+
|
|
276
|
+
```move
|
|
277
|
+
public struct Balance<phantom T> has store {
|
|
278
|
+
value: u64,
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Default Behavior
|
|
283
|
+
|
|
284
|
+
By default, codegen excludes phantom type parameters from the generated BCS type functions since
|
|
285
|
+
they don't affect serialization. The generated type is a constant rather than a function:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
|
|
289
|
+
name: `${$moduleName}::Balance<phantom T>`,
|
|
290
|
+
fields: {
|
|
291
|
+
value: bcs.u64(),
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
This works correctly for parsing on-chain data because phantom types don't change the binary layout.
|
|
297
|
+
|
|
298
|
+
> **Note:** With the default behavior, phantom parameters appear as literals in the type name (e.g.,
|
|
299
|
+
> `Balance<phantom T>`). These names are useful for debugging but are not valid on-chain type tags. If
|
|
300
|
+
> you need valid type names with resolved phantom parameters, enable `includePhantomTypeParameters`.
|
|
301
|
+
|
|
302
|
+
### Including Phantom Type Parameters
|
|
303
|
+
|
|
304
|
+
If you need the phantom type parameters as function arguments (for example, to preserve type
|
|
305
|
+
information for other tooling), enable `includePhantomTypeParameters`:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
const config: SuiCodegenConfig = {
|
|
309
|
+
output: './src/contracts',
|
|
310
|
+
includePhantomTypeParameters: true,
|
|
311
|
+
packages: [
|
|
312
|
+
// ...
|
|
313
|
+
],
|
|
314
|
+
};
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
With this option enabled, phantom type parameters become function arguments:
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
|
|
321
|
+
return new MoveStruct({
|
|
322
|
+
name: `${$moduleName}::Balance<${T.name}>` as const,
|
|
323
|
+
fields: {
|
|
324
|
+
value: bcs.u64(),
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Using Generated Code
|
|
331
|
+
|
|
332
|
+
### Calling Move Functions
|
|
333
|
+
|
|
334
|
+
The generated code provides type-safe functions for calling Move functions:
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
|
|
338
|
+
// Increment a counter
|
|
339
|
+
const tx = new Transaction();
|
|
340
|
+
tx.add(
|
|
341
|
+
counter.increment({
|
|
342
|
+
arguments: {
|
|
343
|
+
counter: '0x123...', // Counter object ID
|
|
344
|
+
},
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Parsing BCS Data
|
|
350
|
+
|
|
351
|
+
Use generated BCS types to parse on-chain object data. Fetch the object with
|
|
352
|
+
`include: { content: true }` and pass `object.content` to the generated type's `.parse()` method:
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
|
|
356
|
+
async function readCounter(client: ClientWithCoreApi, id: string) {
|
|
357
|
+
const { object } = await client.core.getObject({
|
|
358
|
+
objectId: id,
|
|
359
|
+
include: { content: true },
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// Parse the Move struct fields from BCS content
|
|
363
|
+
const parsed = CounterStruct.parse(object.content);
|
|
364
|
+
console.log('Counter value:', parsed.value);
|
|
365
|
+
console.log('Counter owner:', parsed.owner);
|
|
366
|
+
|
|
367
|
+
return parsed;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
> **Warning:** Always use `content`, not `objectBcs`, when parsing with generated types. The `objectBcs` field
|
|
372
|
+
> contains a full object envelope with additional metadata that will cause parsing to fail. See the
|
|
373
|
+
> [Core API docs](/sui/clients/core#objectbcs) for details.
|
|
374
|
+
|
|
375
|
+
## Client Configuration
|
|
376
|
+
|
|
377
|
+
### Using with MVR (Move Version Registry)
|
|
378
|
+
|
|
379
|
+
If your package is registered on MVR, the generated code works without additional configuration.
|
|
380
|
+
|
|
381
|
+
### Local Packages
|
|
382
|
+
|
|
383
|
+
For local packages using `@local-pkg/*` identifiers, configure your client with package overrides:
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
|
|
387
|
+
const client = new SuiGrpcClient({
|
|
388
|
+
network: 'testnet',
|
|
389
|
+
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
390
|
+
mvr: {
|
|
391
|
+
overrides: {
|
|
392
|
+
packages: {
|
|
393
|
+
'@local-pkg/counter': '0xYOUR_PACKAGE_ID',
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### With dApp Kit
|
|
401
|
+
|
|
402
|
+
Configure package overrides when creating your dApp Kit instance:
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
|
|
406
|
+
const GRPC_URLS = {
|
|
407
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const PACKAGE_IDS = {
|
|
411
|
+
testnet: {
|
|
412
|
+
counter: '0xYOUR_PACKAGE_ID',
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const dAppKit = createDAppKit({
|
|
417
|
+
networks: ['testnet'],
|
|
418
|
+
createClient: (network) => {
|
|
419
|
+
return new SuiGrpcClient({
|
|
420
|
+
network,
|
|
421
|
+
baseUrl: GRPC_URLS[network],
|
|
422
|
+
mvr: {
|
|
423
|
+
overrides: {
|
|
424
|
+
packages: {
|
|
425
|
+
'@local-pkg/counter': PACKAGE_IDS[network].counter,
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## Related Resources
|
|
435
|
+
|
|
436
|
+
- [create-dapp](/dapp-kit/getting-started/create-dapp) - Bootstrap a working dApp with codegen
|
|
437
|
+
already configured
|
|
438
|
+
- [Sui Move documentation](https://docs.sui.io/concepts/sui-move-concepts)
|
|
439
|
+
- [BCS documentation](/bcs)
|
|
440
|
+
- [Transaction building](/sui/transaction-building/basics)
|
|
441
|
+
- [dApp Kit](/dapp-kit)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Connect Wallet
|
|
2
|
+
|
|
3
|
+
> Programmatically connect to a Sui wallet
|
|
4
|
+
|
|
5
|
+
The dApp Kit SDK provides an action for wallet connection, allowing users to connect, disconnect,
|
|
6
|
+
and switch between wallets and accounts.
|
|
7
|
+
|
|
8
|
+
> The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
|
|
9
|
+
> connection UI.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
> Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
|
|
14
|
+
> page reload. This provides a seamless user experience but can be
|
|
15
|
+
> [disabled](../dapp-kit-instance#disabling-auto-connect) if needed.
|
|
16
|
+
|
|
17
|
+
The `connectWallet` action prompts a wallet to connect and authorize accounts for your application:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
|
|
21
|
+
const dAppKit = createDAppKit({
|
|
22
|
+
/* config */
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Connect to a specific wallet
|
|
26
|
+
const result = await dAppKit.connectWallet({
|
|
27
|
+
wallet: myWallet, // UiWallet instance
|
|
28
|
+
account: myAccount, // Optional: specific account to select
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log('Connected accounts:', result.accounts);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Parameters
|
|
35
|
+
|
|
36
|
+
- **`wallet`** - The `UiWallet` instance to connect to
|
|
37
|
+
- **`account`** (optional) - A specific `UiWalletAccount` to set as the selected account. Defaults
|
|
38
|
+
to the first authorized account
|
|
39
|
+
|
|
40
|
+
## Return Value
|
|
41
|
+
|
|
42
|
+
Returns a `Promise` that resolves to an object containing:
|
|
43
|
+
|
|
44
|
+
- **`accounts`** - Array of authorized `UiWalletAccount` instances
|
|
45
|
+
|
|
46
|
+
## Example
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const wallets = dAppKit.stores.$wallets.get();
|
|
50
|
+
|
|
51
|
+
const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
|
|
52
|
+
if (connection.isConnected) {
|
|
53
|
+
console.log(`Connected account address: ${connection.account.address}`);
|
|
54
|
+
} else {
|
|
55
|
+
console.log({ connection });
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (wallets.length > 0) {
|
|
60
|
+
try {
|
|
61
|
+
const { accounts } = await dAppKit.connectWallet({
|
|
62
|
+
wallet: wallets[0],
|
|
63
|
+
});
|
|
64
|
+
console.log('Available accounts:', accounts);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Connection failed:', error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Disconnect Wallet
|
|
2
|
+
|
|
3
|
+
> Programmatically disconnect from a Sui wallet
|
|
4
|
+
|
|
5
|
+
The `disconnectWallet` action terminates the connection with the currently connected wallet.
|
|
6
|
+
|
|
7
|
+
> The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
|
|
8
|
+
> connection UI.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
> **Note:** The disconnect action clears the connection state locally and attempts to notify the wallet. Even
|
|
13
|
+
> if the wallet notification fails, the local state is always cleared to ensure a clean
|
|
14
|
+
> disconnection.
|
|
15
|
+
>
|
|
16
|
+
> Note that wallets may or may not implement the `disconnect` feature. Calling `disconnectWallet`
|
|
17
|
+
> doesn't necessarily mean that the wallet accounts will be disconnected from the dApp within the
|
|
18
|
+
> wallet itself - this is determined by each wallet's implementation.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
|
|
22
|
+
const dAppKit = createDAppKit({
|
|
23
|
+
/* config */
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await dAppKit.disconnectWallet();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Parameters
|
|
30
|
+
|
|
31
|
+
None.
|
|
32
|
+
|
|
33
|
+
## Return Value
|
|
34
|
+
|
|
35
|
+
Returns a `Promise` that resolves to `void` when the disconnection is complete.
|
|
36
|
+
|
|
37
|
+
> The action may throw `WalletNotConnectedError` if no wallet is connected. However, wallet-specific
|
|
38
|
+
> disconnect failures are logged but don't prevent the local connection state from being cleared.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Sign and Execute Transaction
|
|
2
|
+
|
|
3
|
+
> Sign and execute a transaction using the connected wallet
|
|
4
|
+
|
|
5
|
+
The `signAndExecuteTransaction` action prompts the connected wallet to sign and immediately execute
|
|
6
|
+
a transaction on the Sui network. This is the most common way to execute transactions in your dApp.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
|
|
12
|
+
const dAppKit = createDAppKit({
|
|
13
|
+
/* config */
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const tx = new Transaction();
|
|
17
|
+
// No need to manually set sender - it's done automatically
|
|
18
|
+
tx.transferObjects([coinWithBalance({ balance: 123 })], '0xrecipient...');
|
|
19
|
+
|
|
20
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
21
|
+
transaction: tx,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (result.FailedTransaction) {
|
|
25
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Parameters
|
|
32
|
+
|
|
33
|
+
- **`transaction`** - `Transaction | string` - The transaction to sign and execute. Can be either a
|
|
34
|
+
Transaction instance or base64-encoded bcs bytes for the transaction.
|
|
35
|
+
- **`signal`** (optional) - `AbortSignal` - An abort signal to cancel the transaction request.
|
|
36
|
+
|
|
37
|
+
## Return Value
|
|
38
|
+
|
|
39
|
+
Returns a `Promise` that resolves to a `TransactionResult` discriminated union:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
type TransactionResult =
|
|
43
|
+
| { $kind: 'Transaction'; Transaction: Transaction }
|
|
44
|
+
| { $kind: 'FailedTransaction'; FailedTransaction: Transaction };
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The `Transaction` object contains:
|
|
48
|
+
|
|
49
|
+
- **`digest`** - `string` - The transaction digest (unique identifier for the executed transaction)
|
|
50
|
+
- **`signatures`** - `string[]` - The signatures as base64-encoded strings
|
|
51
|
+
- **`epoch`** - `string | null` - The epoch in which the transaction was executed
|
|
52
|
+
- **`status`** - `ExecutionStatus` - The execution status with `success: boolean` and
|
|
53
|
+
`error: string | null`
|
|
54
|
+
- **`effects`** - `TransactionEffects | null` - The parsed transaction effects (may be `null` if
|
|
55
|
+
effects parsing fails for unknown effect versions)
|
|
56
|
+
- **`transaction`** - `TransactionData` - The parsed transaction data
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction });
|
|
60
|
+
|
|
61
|
+
if (result.FailedTransaction) {
|
|
62
|
+
console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Access the successful transaction results
|
|
67
|
+
const tx = result.Transaction;
|
|
68
|
+
console.log('Digest:', tx.digest);
|
|
69
|
+
console.log('Signatures:', tx.signatures);
|
|
70
|
+
console.log('Epoch:', tx.epoch);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Transaction Building
|
|
74
|
+
|
|
75
|
+
When passing a Transaction instance, the action automatically:
|
|
76
|
+
|
|
77
|
+
1. Sets the sender address if not already set
|
|
78
|
+
2. Builds the transaction using the current network's client
|
|
79
|
+
3. Converts it to the appropriate format for the wallet
|
|
80
|
+
4. Submits the transaction to the network
|
|
81
|
+
|
|
82
|
+
## Wallet Compatibility
|
|
83
|
+
|
|
84
|
+
- The action transparently handles both `sui:signAndExecuteTransaction` and
|
|
85
|
+
`sui:signAndExecuteTransactionBlock` wallet-standard features
|
|
86
|
+
- The wallet handles network submission and response
|
|
87
|
+
- Some wallets (Enoki, Enoki Connect, WalletConnect) may use the dApp Kit client and execute
|
|
88
|
+
transactions within the application as an implementation detail
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// The action automatically detects and uses the appropriate method
|
|
92
|
+
// No special configuration needed
|
|
93
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
94
|
+
transaction: tx,
|
|
95
|
+
});
|
|
96
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Sign Personal Message
|
|
2
|
+
|
|
3
|
+
> Sign an arbitrary message with the connected wallet
|
|
4
|
+
|
|
5
|
+
The `signPersonalMessage` action prompts the connected wallet to sign a personal message. This is
|
|
6
|
+
useful for authentication, proof of ownership, or other scenarios where you need cryptographic proof
|
|
7
|
+
that a user controls a specific account.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
|
|
13
|
+
const dAppKit = createDAppKit({
|
|
14
|
+
/* config */
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const message = new TextEncoder().encode('Please sign this message');
|
|
18
|
+
const result = await dAppKit.signPersonalMessage({
|
|
19
|
+
message,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
console.log('Message bytes:', result.bytes);
|
|
23
|
+
console.log('Signature:', result.signature);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Parameters
|
|
27
|
+
|
|
28
|
+
- **`message`** - `Uint8Array` - The message to sign as a byte array
|
|
29
|
+
|
|
30
|
+
## Return Value
|
|
31
|
+
|
|
32
|
+
Returns a `Promise` that resolves to an object containing:
|
|
33
|
+
|
|
34
|
+
- **`bytes`** - `string` - Base64 encoded message bytes
|
|
35
|
+
- **`signature`** - `string` - Base64 encoded signature
|
|
36
|
+
|
|
37
|
+
## Message Format
|
|
38
|
+
|
|
39
|
+
The message parameter must be a `Uint8Array`. Common patterns for creating byte arrays:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const textMessage = new TextEncoder().encode('Hello, Sui!');
|
|
43
|
+
await dAppKit.signPersonalMessage({ message: textMessage });
|
|
44
|
+
|
|
45
|
+
const jsonMessage = new TextEncoder().encode(
|
|
46
|
+
JSON.stringify({ action: 'sign', timestamp: Date.now() }),
|
|
47
|
+
);
|
|
48
|
+
await dAppKit.signPersonalMessage({ message: jsonMessage });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Security Considerations
|
|
52
|
+
|
|
53
|
+
### Message Content
|
|
54
|
+
|
|
55
|
+
- Always display the message content clearly to users before signing
|
|
56
|
+
- Avoid signing opaque or encoded data that users cannot understand
|
|
57
|
+
- Include human-readable prefixes for different message types
|
|
58
|
+
- Consider adding timestamps to prevent replay attacks
|