@mysten/sui 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/bcs/bcs.d.mts +6 -6
  3. package/dist/bcs/index.d.mts +20 -20
  4. package/dist/client/types.d.mts +17 -0
  5. package/dist/client/types.d.mts.map +1 -1
  6. package/dist/cryptography/signature.d.mts +14 -14
  7. package/dist/graphql/core.d.mts.map +1 -1
  8. package/dist/graphql/core.mjs +21 -8
  9. package/dist/graphql/core.mjs.map +1 -1
  10. package/dist/graphql/generated/queries.d.mts.map +1 -1
  11. package/dist/graphql/generated/queries.mjs +18 -3
  12. package/dist/graphql/generated/queries.mjs.map +1 -1
  13. package/dist/graphql/generated/tada-env.d.mts +703 -73
  14. package/dist/grpc/core.d.mts.map +1 -1
  15. package/dist/grpc/core.mjs +15 -2
  16. package/dist/grpc/core.mjs.map +1 -1
  17. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  18. package/dist/grpc/proto/sui/rpc/v2/object.d.mts +38 -1
  19. package/dist/grpc/proto/sui/rpc/v2/object.d.mts.map +1 -1
  20. package/dist/grpc/proto/sui/rpc/v2/object.mjs +26 -1
  21. package/dist/grpc/proto/sui/rpc/v2/object.mjs.map +1 -1
  22. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  23. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  24. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  25. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  26. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +8 -0
  27. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
  28. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs +23 -12
  29. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
  30. package/dist/grpc/proto/types.d.mts +2 -2
  31. package/dist/grpc/proto/types.mjs +2 -1
  32. package/dist/jsonRpc/core.d.mts.map +1 -1
  33. package/dist/jsonRpc/core.mjs +10 -3
  34. package/dist/jsonRpc/core.mjs.map +1 -1
  35. package/dist/keypairs/passkey/keypair.d.mts +11 -4
  36. package/dist/keypairs/passkey/keypair.d.mts.map +1 -1
  37. package/dist/keypairs/passkey/keypair.mjs +19 -6
  38. package/dist/keypairs/passkey/keypair.mjs.map +1 -1
  39. package/dist/transactions/Transaction.d.mts +9 -9
  40. package/dist/transactions/Transaction.d.mts.map +1 -1
  41. package/dist/version.mjs +2 -2
  42. package/dist/version.mjs.map +1 -1
  43. package/dist/zklogin/bcs.d.mts +14 -14
  44. package/docs/bcs.md +131 -0
  45. package/docs/clients/core.md +601 -0
  46. package/docs/clients/graphql.md +99 -0
  47. package/docs/clients/grpc.md +152 -0
  48. package/docs/clients/index.md +93 -0
  49. package/docs/clients/json-rpc.md +235 -0
  50. package/docs/cryptography/keypairs.md +258 -0
  51. package/docs/cryptography/multisig.md +192 -0
  52. package/docs/cryptography/passkey.md +111 -0
  53. package/docs/cryptography/webcrypto-signer.md +81 -0
  54. package/docs/executors.md +147 -0
  55. package/docs/faucet.md +26 -0
  56. package/docs/hello-sui.md +114 -0
  57. package/docs/index.md +54 -0
  58. package/docs/install.md +61 -0
  59. package/docs/llm-docs.md +32 -0
  60. package/docs/llms-index.md +60 -0
  61. package/docs/migrations/0.38.md +57 -0
  62. package/docs/migrations/sui-1.0.md +453 -0
  63. package/docs/migrations/sui-2.0/agent-prompt.md +42 -0
  64. package/docs/migrations/sui-2.0/dapp-kit.md +350 -0
  65. package/docs/migrations/sui-2.0/deepbook-v3.md +33 -0
  66. package/docs/migrations/sui-2.0/index.md +157 -0
  67. package/docs/migrations/sui-2.0/json-rpc-migration.md +383 -0
  68. package/docs/migrations/sui-2.0/kiosk.md +120 -0
  69. package/docs/migrations/sui-2.0/sdk-maintainers.md +90 -0
  70. package/docs/migrations/sui-2.0/seal.md +14 -0
  71. package/docs/migrations/sui-2.0/sui.md +341 -0
  72. package/docs/migrations/sui-2.0/suins.md +42 -0
  73. package/docs/migrations/sui-2.0/wallet-builders.md +66 -0
  74. package/docs/migrations/sui-2.0/walrus.md +41 -0
  75. package/docs/migrations/sui-2.0/zksend.md +94 -0
  76. package/docs/plugins.md +255 -0
  77. package/docs/sdk-building.md +340 -0
  78. package/docs/transaction-building/basics.md +297 -0
  79. package/docs/transaction-building/gas.md +62 -0
  80. package/docs/transaction-building/intents.md +61 -0
  81. package/docs/transaction-building/offline.md +71 -0
  82. package/docs/transaction-building/sponsored-transactions.md +22 -0
  83. package/docs/utils/derived_objects.md +59 -0
  84. package/docs/utils/index.md +52 -0
  85. package/docs/zklogin.md +78 -0
  86. package/package.json +5 -3
  87. package/src/client/types.ts +16 -0
  88. package/src/graphql/core.ts +34 -13
  89. package/src/graphql/generated/queries.ts +252 -14
  90. package/src/graphql/generated/schema.graphql +324 -8
  91. package/src/graphql/generated/tada-env.ts +844 -99
  92. package/src/graphql/queries/objects.graphql +10 -0
  93. package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -1
  94. package/src/grpc/core.ts +34 -0
  95. package/src/grpc/proto/sui/rpc/v2/object.ts +44 -0
  96. package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +16 -0
  97. package/src/jsonRpc/core.ts +9 -0
  98. package/src/keypairs/passkey/keypair.ts +20 -6
  99. package/src/version.ts +2 -2
@@ -0,0 +1,255 @@
1
+ # Transaction Plugins
2
+
3
+ > Extend transaction building with reusable plugins
4
+
5
+ > **Warning:** The `Transaction` plugin API is experimental and may change rapidly as it is being
6
+ > developed.
7
+
8
+ This document describes the plugin API for the `Transaction` builder. It covers internal details
9
+ intended for developers interested in extending the `Transaction` builder. Developers using the
10
+ `Transaction` builder to build transactions do not need this level of detail. The `Transaction`
11
+ builder includes a plugin system designed to extend how transactions are built. The two primary
12
+ goals are:
13
+
14
+ 1. Allow developers to customize how data is resolved when building transactions.
15
+ 2. Provide a way for developers to extend the core commands that can be added to transactions.
16
+
17
+ The Plugin API consists of three main components: serialization plugins, build plugins, and
18
+ Transaction Intents. Serialization and build plugins act like middleware, allowing developers to
19
+ modify the data and commands added to a transaction before it is serialized to JSON or built into
20
+ BCS bytes. Transaction Intents are custom representations of user intents for a transaction,
21
+ eventually resolved to one or more commands in the transaction.
22
+
23
+ ## Contents of a Transaction
24
+
25
+ When a `Transaction` is created (e.g., `new Transaction()`), it is initialized with an empty
26
+ [TransactionDataBuilder](/typedoc/classes/_mysten_sui.transactions.TransactionDataBuilder.html)
27
+ instance which stores the state of the partially built transaction. The full API of the
28
+ `TransactionDataBuilder` won't be covered here, but you can find the available methods and
29
+ properties in the
30
+ [typedoc definition](/typedoc/classes/_mysten_sui.transactions.TransactionDataBuilder.html).
31
+
32
+ As commands are added to the `Transaction`, they are stored in the `TransactionDataBuilder`. The
33
+ `TransactionData` contains a list of commands and their arguments. The exact arguments a command
34
+ takes depend on the command, but they will be one of a few different types:
35
+
36
+ - `GasCoin`: A reference to the coin used to pay for gas.
37
+ - `Input`: An input to the transaction (described below).
38
+ - `Result`: The result of a previous command.
39
+ - `NestedResult`: If a previous command returns a tuple (e.g., `SplitCoin`), a `NestedResult` is
40
+ used to refer to a specific value in that tuple.
41
+
42
+ Transactions also store a list of Inputs, which refer to user-provided values. Inputs can either be
43
+ objects or Pure values and can be represented in several different ways:
44
+
45
+ - `Pure`: An input value serialized to BCS. Pure values are generally scalar values or simple
46
+ wrappers like options or vectors and cannot represent object types.
47
+ - `Object`: A fully resolved object reference, which will be one of the following types:
48
+ - `ImmOrOwnedObject`: A reference to an object, including the object's `id`, `version`, and
49
+ `digest`.
50
+ - `SharedObject`: A reference to a shared object, including the object's `id`,
51
+ `initialSharedVersion`, and whether the shared object is used mutably.
52
+ - `Receiving`: A reference to a receiving object, including the object's `id`, `version`, and
53
+ `digest`.
54
+ - `UnresolvedPure`: A placeholder for a pure value that has not been serialized to BCS.
55
+ - `UnresolvedObject`: A partial reference to an object, often containing just the object's `id`, but
56
+ may also include a version, digest, or initialSharedVersion.
57
+
58
+ ## Lifecycle of a Transaction
59
+
60
+ Because transactions can contain `UnresolvedPure` and `UnresolvedObject` inputs, these values need
61
+ to be resolved before the transaction can be serialized to BCS. However, these unresolved inputs can
62
+ be represented in JSON. What may not be able to be represented in JSON are Transaction Intents.
63
+ Transaction Intents represent custom concepts added by plugins or third-party SDKs. To account for
64
+ this, the build process of a transaction is split into two phases: serialization and building.
65
+ Serialization prepares the transaction to be serialized to JSON by running serialization plugins,
66
+ and resolving any unsupported intents. The Build phase then runs, which runs build plugins and
67
+ resolves any UnresolvedPure and UnresolvedObject inputs, before the transaction is serialized to
68
+ BCS.
69
+
70
+ ## Serialization Plugins
71
+
72
+ Serialization plugins can be added to a `Transaction` by calling the `addSerializationPlugin` method
73
+ on a `Transaction` instance. Serialization plugins are called in the order they are added and are
74
+ passed the `TransactionDataBuilder` instance of the transaction.
75
+
76
+ ```typescript
77
+ const transaction = new Transaction();
78
+
79
+ transaction.addSerializationPlugin(async (transactionData, buildOptions, next) => {
80
+ // Modify the data before running other serialization steps
81
+ await next();
82
+ // Modify the data after running other serialization steps
83
+ });
84
+ ```
85
+
86
+ ## Build Plugins
87
+
88
+ The build phase is responsible for taking unresolved objects and unresolved pure values and
89
+ converting them to their resolved versions by querying the RPC API to fetch the missing data. Build
90
+ plugins can hook into this phase to resolve some of this data from a cache instead, avoiding extra
91
+ API calls.
92
+
93
+ Build plugins work just like serialization plugins and can be added to a `Transaction` by calling
94
+ the `addBuildPlugin` method on a `Transaction` instance. Build plugins are called in the order they
95
+ are added and are passed the `TransactionDataBuilder` instance of the transaction.
96
+
97
+ The following example demonstrates a simplified version of the caching plugin used by the
98
+ `SerialTransactionExecutor` and `ParallelTransactionExecutor` classes. This example works by adding
99
+ missing object versions and digest from a cache. Updating the cache (which could be done by looking
100
+ at transaction effects of previous transactions) is not covered in this example.
101
+
102
+ ```typescript
103
+
104
+ BuildTransactionOptions,
105
+ Transaction,
106
+ TransactionDataBuilder,
107
+ } from '@mysten/sui/transactions';
108
+
109
+ const objectCache = new Map<string, { objectId: string; version: string; digest: string }>();
110
+
111
+ function simpleObjectCachePlugin(
112
+ transactionData: TransactionDataBuilder,
113
+ _options: BuildTransactionOptions,
114
+ next: () => Promise<void>,
115
+ ) {
116
+ for (const input of transactionData.inputs) {
117
+ if (!input.UnresolvedObject) continue;
118
+
119
+ const cached = objectCache.get(input.UnresolvedObject.objectId);
120
+
121
+ if (!cached) continue;
122
+
123
+ if (cached.version && !input.UnresolvedObject.version) {
124
+ input.UnresolvedObject.version = cached.version;
125
+ }
126
+
127
+ if (cached.digest && !input.UnresolvedObject.digest) {
128
+ input.UnresolvedObject.digest = cached.digest;
129
+ }
130
+ }
131
+
132
+ return next();
133
+ }
134
+
135
+ // Example usage of the build plugin
136
+ const transaction = new Transaction();
137
+ transaction.addBuildPlugin(simpleObjectCachePlugin);
138
+ ```
139
+
140
+ ## Transaction Intents
141
+
142
+ Transaction Intents consist of two parts: adding the intent to the transaction and resolving the
143
+ intent to standard commands.
144
+
145
+ Adding an intent is similar to adding any other command to a transaction:
146
+
147
+ ```typescript
148
+ const transaction = new Transaction();
149
+
150
+ transaction.add(
151
+ Commands.Intent({
152
+ name: 'TransferToSender',
153
+ inputs: {
154
+ objects: [transaction.object(someId)],
155
+ },
156
+ }),
157
+ );
158
+ ```
159
+
160
+ To make our custom `TransferToSender` intent easier to use, we can write a helper function that
161
+ wraps things up a bit. The `add` method on transactions accepts a function that will be passed the
162
+ current transaction instance. This allows us to create a helper that automatically adds the intent:
163
+
164
+ ```typescript
165
+ function transferToSender(objects: TransactionObjectInput[]) {
166
+ return (tx: Transaction) => {
167
+ tx.add(
168
+ Commands.Intent({
169
+ name: 'TransferToSender',
170
+ inputs: {
171
+ objects: objects.map((obj) => tx.object(obj)),
172
+ },
173
+ }),
174
+ );
175
+ };
176
+ }
177
+
178
+ const transaction = new Transaction();
179
+
180
+ transaction.add(transferToSender(['0x1234']));
181
+ ```
182
+
183
+ Now that we've added the intent to the transaction, we need to resolve the intent to standard
184
+ commands. To do this, we'll use the `addIntentResolver` method on the `Transaction` instance. The
185
+ `addIntentResolver` method works like serialization and build plugins but will only be called if the
186
+ intent is present in the transaction.
187
+
188
+ ```typescript
189
+ const transaction = new Transaction();
190
+
191
+ transaction.addIntentResolver('TransferToSender', resolveTransferToSender);
192
+
193
+ async function resolveTransferToSender(
194
+ transactionData: TransactionDataBuilder,
195
+ buildOptions: BuildTransactionOptions,
196
+ next: () => Promise<void>,
197
+ ) {
198
+ if (!transactionData.sender) {
199
+ throw new Error('Sender must be set to resolve TransferToSender');
200
+ }
201
+
202
+ // Add an input that references the sender's address
203
+ const addressInput = Inputs.Pure(bcs.Address.serialize(transactionData.sender));
204
+ transactionData.inputs.push(addressInput);
205
+ // Get the index of the input to use when adding the TransferObjects command
206
+ const addressIndex = transactionData.inputs.length - 1;
207
+
208
+ for (const [index, transaction] of transactionData.commands.entries()) {
209
+ if (transaction.$kind !== '$Intent' || transaction.$Intent.name !== 'TransferToSender') {
210
+ continue;
211
+ }
212
+
213
+ // This will replace the intent command with the correct TransferObjects command
214
+ transactionData.replaceCommand(index, [
215
+ Commands.TransferObjects(
216
+ // The inputs for intents are not currently typed, so we need to cast to the correct type here
217
+ transaction.$Intent.inputs.objects as Extract<
218
+ TransactionObjectArgument,
219
+ { $kind: 'Input' }
220
+ >,
221
+ // This is a CallArg referencing the addressInput we added above
222
+ {
223
+ Input: addressIndex,
224
+ },
225
+ ),
226
+ ]);
227
+ }
228
+
229
+ // Plugins always need to call next() to continue the build process
230
+ return next();
231
+ }
232
+ ```
233
+
234
+ Manually adding intent resolvers to a transaction can be cumbersome, so we can add the resolver
235
+ automatically when our `transferToSender` helper is called:
236
+
237
+ ```typescript
238
+ function transferToSender(objects: TransactionObjectInput[]) {
239
+ return (tx: Transaction) => {
240
+ // As long as we are adding the same function reference, it will only be added once
241
+ tx.addIntentResolver('TransferToSender', resolveTransferToSender);
242
+ tx.add(
243
+ Commands.Intent({
244
+ name: 'TransferToSender',
245
+ inputs: {
246
+ objects: objects.map((obj) => tx.object(obj)),
247
+ },
248
+ }),
249
+ );
250
+ };
251
+ }
252
+
253
+ const transaction = new Transaction();
254
+ transaction.add(transferToSender(['0x1234']));
255
+ ```
@@ -0,0 +1,340 @@
1
+ # Building SDKs
2
+
3
+ > Build custom SDKs on top of the Sui TypeScript SDK
4
+
5
+ This guide covers recommended patterns for building TypeScript SDKs that integrate with the Sui SDK.
6
+ Following these patterns ensures your SDK integrates seamlessly with the ecosystem, works across
7
+ different transports (JSON-RPC, GraphQL, gRPC), and composes well with other SDKs.
8
+
9
+ **Key requirement:** All SDKs should depend on [`ClientWithCoreApi`](./clients/core), which is the
10
+ transport-agnostic interface implemented by all Sui clients. This ensures your SDK works with any
11
+ client the user chooses.
12
+
13
+ ## Package Setup
14
+
15
+ ### Use Mysten Packages as Peer Dependencies
16
+
17
+ SDKs should declare all `@mysten/*` packages as **peer dependencies** rather than direct
18
+ dependencies. This ensures users get a single shared instance of each package, avoiding version
19
+ conflicts and duplicate code.
20
+
21
+ ```json title="package.json"
22
+ {
23
+ "name": "@your-org/your-sdk",
24
+ "peerDependencies": {
25
+ "@mysten/sui": "^2.0.0",
26
+ "@mysten/bcs": "^2.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@mysten/sui": "^2.0.0",
30
+ "@mysten/bcs": "^2.0.0"
31
+ }
32
+ }
33
+ ```
34
+
35
+ This approach:
36
+
37
+ - Prevents multiple versions of Mysten packages from being bundled
38
+ - Ensures compatibility with user's chosen package versions
39
+ - Reduces bundle size for end users
40
+ - Avoids subtle bugs from mismatched package instances
41
+ - Allows the SDK to work with any compatible client
42
+
43
+ ## Client Extensions
44
+
45
+ The recommended way to build SDKs is using the **client extension pattern**. This allows your SDK to
46
+ extend the Sui client with custom functionality. This makes it easier to use custom SDKs across the
47
+ ecosystem without having to build custom bindings (like react context providers) for each individual
48
+ SDK and client.
49
+
50
+ ### Extension Pattern
51
+
52
+ Client extensions use the `$extend` method to add functionality to any Sui client. Create a factory
53
+ function that returns a `name` and `register` function:
54
+
55
+ ```typescript
56
+
57
+ name?: Name;
58
+ // Add SDK-specific configuration here
59
+ apiKey?: string;
60
+ }
61
+
62
+ name = 'mySDK' as Name,
63
+ ...options
64
+ }: MySDKOptions<Name> = {}) {
65
+ return {
66
+ name,
67
+ register: (client: ClientWithCoreApi) => {
68
+ return new MySDKClient({ client, ...options });
69
+ },
70
+ };
71
+ }
72
+
73
+ #client: ClientWithCoreApi;
74
+ #apiKey?: string;
75
+
76
+ constructor({ client, apiKey }: { client: ClientWithCoreApi; apiKey?: string }) {
77
+ this.#client = client;
78
+ this.#apiKey = apiKey;
79
+ }
80
+
81
+ async getResource(id: string) {
82
+ const result = await this.#client.core.getObject({ objectId: id });
83
+ // Process and return result
84
+ return result;
85
+ }
86
+ }
87
+ ```
88
+
89
+ Users can then extend their client:
90
+
91
+ ```typescript
92
+ const client = new SuiGrpcClient({
93
+ network: 'testnet',
94
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
95
+ }).$extend(mySDK());
96
+
97
+ // Access your extension
98
+ await client.mySDK.getResource('0x...');
99
+ ```
100
+
101
+ ### Real-World Examples
102
+
103
+ Several official SDKs use this pattern:
104
+
105
+ - **[@mysten/walrus](https://www.npmjs.com/package/@mysten/walrus)** - Decentralized storage
106
+ - **[@mysten/seal](https://www.npmjs.com/package/@mysten/seal)** - Encryption and key management
107
+
108
+ ## SDK Organization
109
+
110
+ Most Mysten SDKs do not strictly follow these patterns yet, but we recommend scoping methods on your
111
+ client extension into the following categories for clarity and consistency:
112
+
113
+ | Property | Purpose | Example |
114
+ | -------- | --------------------------------------------------------- | ----------------------------------- |
115
+ | Methods | Top-level operations (execute actions or read/parse data) | `sdk.readBlob()`, `sdk.getConfig()` |
116
+ | `tx` | Methods that create transactions without executing | `sdk.tx.registerBlob()` |
117
+ | `bcs` | BCS type definitions for encoding/decoding | `sdk.bcs.MyStruct` |
118
+ | `call` | Methods returning Move calls that can be used with tx.add | `sdk.call.myFunction()` |
119
+ | `view` | Methods that use simulate API to read onchain state | `sdk.view.getState()` |
120
+
121
+ ```typescript
122
+
123
+ #client: ClientWithCoreApi;
124
+
125
+ constructor({ client }: { client: ClientWithCoreApi }) {
126
+ this.#client = client;
127
+ }
128
+
129
+ // Top-level methods - execute actions or read/parse data
130
+ async executeAction(options: ActionOptions) {
131
+ const transaction = this.tx.createAction(options);
132
+ // Execute and return result
133
+ }
134
+
135
+ async getResource(objectId: string) {
136
+ const { object } = await this.#client.core.getObject({
137
+ objectId,
138
+ include: { content: true },
139
+ });
140
+ return myModule.MyStruct.parse(object.content);
141
+ }
142
+
143
+ // Transaction builders
144
+ tx = {
145
+ createAction: (options: ActionOptions) => {
146
+ const transaction = new Transaction();
147
+ transaction.add(this.call.action(options));
148
+ return transaction;
149
+ },
150
+ };
151
+
152
+ // Move call helpers - use generated functions with typed options
153
+ call = {
154
+ action: (options: ActionOptions) => {
155
+ return myModule.action({
156
+ arguments: {
157
+ obj: options.objectId,
158
+ amount: options.amount,
159
+ },
160
+ });
161
+ },
162
+ };
163
+
164
+ // View methods - use simulate API to read onchain state
165
+ view = {
166
+ getBalance: async (managerId: string) => {
167
+ const tx = new Transaction();
168
+ tx.add(myModule.getBalance({ arguments: { manager: managerId } }));
169
+
170
+ const res = await this.#client.core.simulateTransaction({
171
+ transaction: tx,
172
+ include: { commandResults: true },
173
+ });
174
+
175
+ return bcs.U64.parse(res.commandResults![0].returnValues[0].bcs);
176
+ },
177
+ };
178
+ }
179
+ ```
180
+
181
+ ## Transaction Building Patterns
182
+
183
+ ### Transaction Thunks
184
+
185
+ Transaction thunks are functions that accept a `Transaction` and mutate it. This pattern enables
186
+ composition across multiple SDKs in a single transaction.
187
+
188
+ ```typescript
189
+ // Synchronous thunk for operations that don't need async work
190
+ function createResource(options: { name: string }) {
191
+ return (tx: Transaction): TransactionObjectArgument => {
192
+ const [resource] = tx.moveCall({
193
+ target: `${PACKAGE_ID}::module::create`,
194
+ arguments: [tx.pure.string(options.name)],
195
+ });
196
+ return resource;
197
+ };
198
+ }
199
+
200
+ // Usage
201
+ const tx = new Transaction();
202
+ const resource = tx.add(createResource({ name: 'my-resource' }));
203
+ tx.transferObjects([resource], recipient);
204
+ ```
205
+
206
+ ### Async Thunks
207
+
208
+ For operations requiring async work (like fetching package IDs or configuration), return async
209
+ thunks. These are used with `tx.add()` exactly like synchronous thunks - the async resolution
210
+ happens automatically before signing:
211
+
212
+ ```typescript
213
+ function createResourceAsync(options: { name: string }) {
214
+ return async (tx: Transaction): Promise<TransactionObjectArgument> => {
215
+ // Async work happens here, before the transaction is signed
216
+ const packageId = await getLatestPackageId();
217
+
218
+ const [resource] = tx.moveCall({
219
+ target: `${packageId}::module::create`,
220
+ arguments: [tx.pure.string(options.name)],
221
+ });
222
+ return resource;
223
+ };
224
+ }
225
+
226
+ // Usage is identical to synchronous thunks
227
+ const tx = new Transaction();
228
+ const resource = tx.add(createResourceAsync({ name: 'my-resource' }));
229
+ tx.transferObjects([resource], recipient);
230
+
231
+ // Async work resolves automatically when the transaction is built/signed
232
+ await signer.signAndExecuteTransaction({ transaction: tx, client });
233
+ ```
234
+
235
+ This pattern is critical for web wallet compatibility - async work that happens during transaction
236
+ construction won't block the popup triggered by user interaction.
237
+
238
+ ## Transaction Execution
239
+
240
+ ### Accept a Signer Parameter
241
+
242
+ For methods that execute transactions, accept a `Signer` parameter and always use the signer to
243
+ execute the transaction. This enables:
244
+
245
+ - Wallet integration through dApp Kit
246
+ - Transaction sponsorship
247
+ - Custom signing flows
248
+
249
+ ```typescript
250
+
251
+ #client: ClientWithCoreApi;
252
+
253
+ async createAndExecute({ signer, ...options }: CreateOptions & { signer: Signer }) {
254
+ const transaction = this.tx.create(options);
255
+
256
+ // Use signAndExecuteTransaction for maximum flexibility
257
+ const result = await signer.signAndExecuteTransaction({
258
+ transaction,
259
+ client: this.#client,
260
+ });
261
+
262
+ return result;
263
+ }
264
+ }
265
+ ```
266
+
267
+ Using `signAndExecuteTransaction` allows wallets and sponsors to customize execution behavior.
268
+
269
+ ## Code Generation
270
+
271
+ For SDKs that interact with Move contracts, use **[@mysten/codegen](/codegen)** to generate
272
+ type-safe TypeScript bindings from your Move packages.
273
+
274
+ Benefits include type safety, BCS parsing, IDE support, and MoveRegistry support for human-readable
275
+ package names. See the [codegen documentation](/codegen) for setup instructions.
276
+
277
+ ### Using Generated Code
278
+
279
+ The generated code provides both Move call functions and BCS struct definitions:
280
+
281
+ ```typescript
282
+ // Generated Move call functions return thunks with typed options
283
+ const tx = new Transaction();
284
+ tx.add(
285
+ myContract.doSomething({
286
+ arguments: {
287
+ obj: '0x123...',
288
+ amount: 100n,
289
+ },
290
+ }),
291
+ );
292
+
293
+ // Generated BCS types parse on-chain data
294
+ const { object } = await client.core.getObject({
295
+ objectId: '0x123...',
296
+ include: { content: true },
297
+ });
298
+ const parsed = myContract.MyStruct.parse(object.content);
299
+ ```
300
+
301
+ See the [codegen documentation](/codegen) for complete setup and configuration options.
302
+
303
+ ## Reading Object Contents
304
+
305
+ SDKs often need to fetch objects and parse their BCS-encoded content. Use `getObject` with
306
+ `include: { content: true }` and generated BCS types:
307
+
308
+ ```typescript
309
+ async function getResource(objectId: string) {
310
+ const { object } = await this.#client.core.getObject({
311
+ objectId,
312
+ include: { content: true },
313
+ });
314
+
315
+ if (!object) {
316
+ throw new Error(`Object ${objectId} not found`);
317
+ }
318
+
319
+ // Parse BCS content using generated type
320
+ return MyStruct.parse(object.content);
321
+ }
322
+ ```
323
+
324
+ For batching multiple object fetches, use `getObjects`:
325
+
326
+ ```typescript
327
+ async function getResources(objectIds: string[]) {
328
+ const { objects } = await this.#client.core.getObjects({
329
+ objectIds,
330
+ include: { content: true },
331
+ });
332
+
333
+ return objects.map((obj) => {
334
+ if (obj instanceof Error) {
335
+ throw obj;
336
+ }
337
+ return MyStruct.parse(obj.content);
338
+ });
339
+ }
340
+ ```