@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,297 @@
1
+ # Sui Programmable Transaction Basics
2
+
3
+ > Construct programmable transaction blocks with the Transaction API
4
+
5
+ This example starts by constructing a transaction to send SUI. To construct transactions, import the
6
+ `Transaction` class and construct it:
7
+
8
+ ```tsx
9
+ const tx = new Transaction();
10
+ ```
11
+
12
+ You can then add commands to the transaction .
13
+
14
+ ```tsx
15
+ // create a new coin with balance 100, based on the coins used as gas payment
16
+ // you can define any balance here
17
+ const [coin] = tx.splitCoins(tx.gas, [100]);
18
+
19
+ // transfer the split coin to a specific address
20
+ tx.transferObjects([coin], '0xSomeSuiAddress');
21
+ ```
22
+
23
+ You can attach multiple commands of the same type to a transaction, as well. For example, to get a
24
+ list of transfers and iterate over them to transfer coins to each of them:
25
+
26
+ ```tsx
27
+ interface Transfer {
28
+ to: string;
29
+ amount: number;
30
+ }
31
+
32
+ // procure a list of some Sui transfers to make
33
+ const transfers: Transfer[] = getTransfers();
34
+
35
+ const tx = new Transaction();
36
+
37
+ // first, split the gas coin into multiple coins
38
+ const coins = tx.splitCoins(
39
+ tx.gas,
40
+ transfers.map((transfer) => transfer.amount),
41
+ );
42
+
43
+ // next, create a transfer command for each coin
44
+ transfers.forEach((transfer, index) => {
45
+ tx.transferObjects([coins[index]], transfer.to);
46
+ });
47
+ ```
48
+
49
+ After you have the transaction defined, you can directly execute it with a signer using
50
+ `signAndExecuteTransaction`.
51
+
52
+ ```tsx
53
+ const result = await client.signAndExecuteTransaction({ signer: keypair, transaction: tx });
54
+
55
+ // IMPORTANT: Always check the transaction status
56
+ // Transactions can execute but still fail (e.g., insufficient gas, move errors)
57
+ if (result.$kind === 'FailedTransaction') {
58
+ throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
59
+ }
60
+ ```
61
+
62
+ ## Observing the results of a transaction
63
+
64
+ When you use `client.signAndExecuteTransaction` or `client.executeTransactionBlock`, the transaction
65
+ will be finalized on the blockchain before the function resolves, but the effects of the transaction
66
+ may not be immediately observable.
67
+
68
+ There are 2 ways to observe the results of a transaction. Methods like
69
+ `client.signAndExecuteTransaction` accept an `options` object with options like `showObjectChanges`
70
+ and `showBalanceChanges` (see
71
+ [the SuiJsonRpcClient docs for more details](/sui/clients/json-rpc#arguments)). These options will
72
+ cause the request to contain additional details about the effects of the transaction that can be
73
+ immediately displayed to the user, or used for further processing in your application.
74
+
75
+ The other way effects of transactions can be observed is by querying other RPC methods like
76
+ `client.getBalances` that return objects or balances owned by a specific address. These RPC calls
77
+ depend on the RPC node having indexed the effects of the transaction, which may not have happened
78
+ immediately after a transaction has been executed. To ensure that effects of a transaction are
79
+ represented in future RPC calls, you can use the `waitForTransaction` method on the client:
80
+
81
+ ```typescript
82
+ const result = await client.signAndExecuteTransaction({ signer: keypair, transaction: tx });
83
+
84
+ // Check transaction status
85
+ if (result.$kind === 'FailedTransaction') {
86
+ throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
87
+ }
88
+
89
+ await client.waitForTransaction({ result });
90
+ ```
91
+
92
+ Once `waitForTransaction` resolves, any future RPC calls will be guaranteed to reflect the effects
93
+ of the transaction.
94
+
95
+ ## Transactions
96
+
97
+ Programmable Transactions have two key concepts: inputs and commands.
98
+
99
+ Commands are steps of execution in the transaction. Each command in a Transaction takes a set of
100
+ inputs, and produces results. The inputs for a transaction depend on the kind of command. Sui
101
+ supports following commands:
102
+
103
+ - `tx.splitCoins(coin, amounts)` - Creates new coins with the defined amounts, split from the
104
+ provided coin. Returns the coins so that it can be used in subsequent transactions.
105
+ - Example: `tx.splitCoins(tx.gas, [100, 200])`
106
+ - `tx.mergeCoins(destinationCoin, sourceCoins)` - Merges the sourceCoins into the destinationCoin.
107
+ - Example: `tx.mergeCoins(tx.object(coin1), [tx.object(coin2), tx.object(coin3)])`
108
+ - `tx.transferObjects(objects, address)` - Transfers a list of objects to the specified address.
109
+ - Example: `tx.transferObjects([tx.object(thing1), tx.object(thing2)], myAddress)`
110
+ - `tx.moveCall({ target, arguments, typeArguments })` - Executes a Move call. Returns whatever the
111
+ Sui Move call returns.
112
+ - Example:
113
+ `tx.moveCall({ target: '0x2::devnet_nft::mint', arguments: [tx.pure.string(name), tx.pure.string(description), tx.pure.string(image)] })`
114
+ - `tx.makeMoveVec({ type, elements })` - Constructs a vector of objects that can be passed into a
115
+ `moveCall`. This is required as there’s no way to define a vector as an input.
116
+ - Example: `tx.makeMoveVec({ elements: [tx.object(id1), tx.object(id2)] })`
117
+ - `tx.publish(modules, dependencies)` - Publishes a Move package. Returns the upgrade capability
118
+ object.
119
+
120
+ ## Passing inputs to a command
121
+
122
+ Command inputs can be provided in a number of different ways, depending on the command, and the type
123
+ of value being provided.
124
+
125
+ #### JavaScript values
126
+
127
+ For specific command arguments (`amounts` in `splitCoins`, and `address` in `transferObjects`) the
128
+ expected type is known ahead of time, and you can directly pass raw javascript values when calling
129
+ the command method. appropriate Move type automatically.
130
+
131
+ ```ts
132
+ // the amount to split off the gas coin is provided as a pure javascript number
133
+ const [coin] = tx.splitCoins(tx.gas, [100]);
134
+ // the address for the transfer is provided as a pure javascript string
135
+ tx.transferObjects([coin], '0xSomeSuiAddress');
136
+ ```
137
+
138
+ #### Pure values
139
+
140
+ When providing inputs that are not on chain objects, the values must be serialized as
141
+
142
+ [BCS](https://sdk.mystenlabs.com/bcs), which can be done using `tx.pure` eg,
143
+ `tx.pure.address(address)` or `tx.pure(bcs.vector(bcs.U8).serialize(bytes))`.
144
+
145
+ `tx.pure` can be called as a function that accepts a SerializedBcs object, or as a namespace that
146
+ contains functions for each of the supported types.
147
+
148
+ ```ts
149
+ const [coin] = tx.splitCoins(tx.gas, [tx.pure.u64(100)]);
150
+ const [coin] = tx.splitCoins(tx.gas, [tx.pure(bcs.U64.serialize(100))]);
151
+ tx.transferObjects([coin], tx.pure.address('0xSomeSuiAddress'));
152
+ tx.transferObjects([coin], tx.pure(bcs.Address.serialize('0xSomeSuiAddress')));
153
+ ```
154
+
155
+ To pass `vector` or `option` types, you can pass use the corresponding methods on `tx.pure`, use
156
+ tx.pure as a function with a type argument, or serialize the value before passing it to tx.pure
157
+ using the bcs sdk:
158
+
159
+ ```ts
160
+ tx.moveCall({
161
+ target: '0x2::foo::bar',
162
+ arguments: [
163
+ // using vector and option methods
164
+ tx.pure.vector('u8', [1, 2, 3]),
165
+ tx.pure.option('u8', 1),
166
+ tx.pure.option('u8', null),
167
+
168
+ // Using pure with type arguments
169
+ tx.pure('vector<u8>', [1, 2, 3]),
170
+ tx.pure('option<u8>', 1),
171
+ tx.pure('option<u8>', null),
172
+ tx.pure('vector<option<u8>>', [1, null, 2]),
173
+
174
+ // Using bcs.serialize
175
+ tx.pure(bcs.vector(bcs.U8).serialize([1, 2, 3])),
176
+ tx.pure(bcs.option(bcs.U8).serialize(1)),
177
+ tx.pure(bcs.option(bcs.U8).serialize(null)),
178
+ tx.pure(bcs.vector(bcs.option(bcs.U8)).serialize([1, null, 2])),
179
+ ],
180
+ });
181
+ ```
182
+
183
+ #### Object references
184
+
185
+ To use an on chain object as a transaction input, you must pass a reference to that object. This can
186
+ be done by calling `tx.object` with the object id. Transaction arguments that only accept objects
187
+ (like `objects` in `transferObjects`) will automatically treat any provided strings as objects ids.
188
+ For methods like `moveCall` that accept both objects and other types, you must explicitly call
189
+ `tx.object` to convert the id to an object reference.
190
+
191
+ ```ts
192
+ // Object IDs can be passed to some methods like (transferObjects) directly
193
+ tx.transferObjects(['0xSomeObject'], 'OxSomeAddress');
194
+ // tx.object can be used anywhere an object is accepted
195
+ tx.transferObjects([tx.object('0xSomeObject')], 'OxSomeAddress');
196
+
197
+ tx.moveCall({
198
+ target: '0x2::nft::mint',
199
+ // object IDs must be wrapped in moveCall arguments
200
+ arguments: [tx.object('0xSomeObject')],
201
+ });
202
+
203
+ // tx.object automatically converts the object ID to receiving transaction arguments if the moveCall expects it
204
+ tx.moveCall({
205
+ target: '0xSomeAddress::example::receive_object',
206
+ // 0xSomeAddress::example::receive_object expects a receiving argument and has a Move definition that looks like this:
207
+ // public fun receive_object<T: key>(parent_object: &mut ParentObjectType, receiving_object: Receiving<ChildObjectType>) { ... }
208
+ arguments: [tx.object('0xParentObjectID'), tx.object('0xReceivingObjectID')],
209
+ });
210
+ ```
211
+
212
+ When building a transaction, Sui expects all objects to be fully resolved, including the object
213
+ version. The SDK automatically looks up the current version of objects for any provided object
214
+ reference when building a transaction. If the object reference is used as a receiving argument to a
215
+ `moveCall`, the object reference is automatically converted to a receiving transaction argument.
216
+ This greatly simplifies building transactions, but requires additional RPC calls. You can optimize
217
+ this process by providing a fully resolved object reference instead:
218
+
219
+ ```ts
220
+ // for owned or immutable objects
221
+ tx.object(Inputs.ObjectRef({ digest, objectId, version }));
222
+
223
+ // for shared objects
224
+ tx.object(Inputs.SharedObjectRef({ objectId, initialSharedVersion, mutable }));
225
+
226
+ // for receiving objects
227
+ tx.object(Inputs.ReceivingRef({ digest, objectId, version }));
228
+ ```
229
+
230
+ ##### Object helpers
231
+
232
+ There are a handful of specific object types that can be referenced through helper methods on
233
+ tx.object:
234
+
235
+ ```ts
236
+ tx.object.system(),
237
+ tx.object.clock(),
238
+ tx.object.random(),
239
+ tx.object.denyList(),
240
+
241
+ tx.object.option({
242
+ type: '0x123::example::Thing',
243
+ // value can be an Object ID, or any other object reference, or null for `none`
244
+ value: '0x456',
245
+ }),
246
+ ```
247
+
248
+ #### Transaction results
249
+
250
+ You can also use the result of a command as an argument in a subsequent commands. Each method on the
251
+ transaction builder returns a reference to the transaction result.
252
+
253
+ ```tsx
254
+ // split a coin object off of the gas object
255
+ const [coin] = tx.splitCoins(tx.gas, [100]);
256
+ // transfer the resulting coin object
257
+ tx.transferObjects([coin], address);
258
+ ```
259
+
260
+ When a command returns multiple results, you can access the result at a specific index either using
261
+ destructuring, or array indexes.
262
+
263
+ ```tsx
264
+ // destructuring (preferred, as it gives you logical local names)
265
+ const [nft1, nft2] = tx.moveCall({ target: '0x2::nft::mint_many' });
266
+ tx.transferObjects([nft1, nft2], address);
267
+
268
+ // array indexes
269
+ const mintMany = tx.moveCall({ target: '0x2::nft::mint_many' });
270
+ tx.transferObjects([mintMany[0], mintMany[1]], address);
271
+ ```
272
+
273
+ ## Get transaction bytes
274
+
275
+ If you need the transaction bytes, instead of signing or executing the transaction, you can use the
276
+ `build` method on the transaction builder itself.
277
+
278
+ **Important:** You might need to explicitly call `setSender()` on the transaction to ensure that the
279
+ `sender` field is populated. This is normally done by the signer before signing the transaction, but
280
+ will not be done automatically if you’re building the transaction bytes yourself.
281
+
282
+ ```tsx
283
+ const tx = new Transaction();
284
+
285
+ // ... add some transactions...
286
+
287
+ await tx.build({ client });
288
+ ```
289
+
290
+ In most cases, building requires your SuiJsonRpcClient to fully resolve input values.
291
+
292
+ If you have transaction bytes, you can also convert them back into a `Transaction` class:
293
+
294
+ ```tsx
295
+ const bytes = getTransactionBytesFromSomewhere();
296
+ const tx = Transaction.from(bytes);
297
+ ```
@@ -0,0 +1,62 @@
1
+ # Paying for Sui Transactions with Gas Coins
2
+
3
+ > Configure gas budget, price, and coin selection for transactions
4
+
5
+ With Programmable Transactions, you can use the gas payment coin to construct coins with a set
6
+ balance using `splitCoin`. This is useful for Sui payments, and avoids the need for up-front coin
7
+ selection. You can use `tx.gas` to access the gas coin in a transaction, and it is valid as input
8
+ for any arguments, as long as it is used
9
+ [by-reference](https://docs.sui.io/guides/developer/sui-101/simulating-refs). Practically speaking,
10
+ this means you can also add to the gas coin with `mergeCoins` and borrow it for Move functions with
11
+ `moveCall`.
12
+
13
+ You can also transfer the gas coin using `transferObjects`, in the event that you want to transfer
14
+ all of your coin balance to another address.
15
+
16
+ ## Gas configuration
17
+
18
+ The new transaction builder comes with default behavior for all gas logic, including automatically
19
+ setting the gas price, budget, and selecting coins to be used as gas. This behavior can be
20
+ customized.
21
+
22
+ ### Gas price
23
+
24
+ By default, the gas price is set to the reference gas price of the network. You can also explicitly
25
+ set the gas price of the transaction by calling `setGasPrice` on the transaction builder.
26
+
27
+ ```tsx
28
+ tx.setGasPrice(gasPrice);
29
+ ```
30
+
31
+ ### Budget
32
+
33
+ By default, the gas budget is automatically derived by executing a dry-run of the transaction
34
+ beforehand. The dry run gas consumption is then used to determine a balance for the transaction. You
35
+ can override this behavior by explicitly setting a gas budget for the transaction, by calling
36
+ `setGasBudget` on the transaction builder.
37
+
38
+ **Note:** The gas budget is represented in Sui, and should take the gas price of the transaction
39
+ into account.
40
+
41
+ ```tsx
42
+ tx.setGasBudget(gasBudgetAmount);
43
+ ```
44
+
45
+ ### Gas payment
46
+
47
+ By default, the gas payment is automatically determined by the SDK. The SDK selects all of the users
48
+ coins that are not used as inputs in the transaction.
49
+
50
+ The list of coins used as gas payment will be merged down into a single gas coin before executing
51
+ the transaction, and all but one of the gas objects will be deleted. The gas coin at the 0-index
52
+ will be the coin that all others are merged into.
53
+
54
+ ```tsx
55
+ // you need to ensure that the coins do not overlap with any
56
+ // of the input objects for the transaction
57
+ tx.setGasPayment([coin1, coin2]);
58
+ ```
59
+
60
+ Gas coins should be objects containing the coins objectId, version, and digest.
61
+
62
+ <auto-type-table type="{ objectId: string, version: string | number, digest: string }" />
@@ -0,0 +1,61 @@
1
+ # Transaction Intents
2
+
3
+ > Use high-level intents to simplify transaction building
4
+
5
+ Transaction Intents enable 3rd party SDKs and [Transaction Plugins](../plugins) to more easily add
6
+ complex operations to a Transaction. The Typescript SDK currently only includes a single Intent
7
+ (CoinWithBalance), but more will be added in the future.
8
+
9
+ ## The CoinWithBalance intent
10
+
11
+ The `CoinWithBalance` intent makes it easy to get a coin with a specific balance. For SUI, this has
12
+ generally been done by splitting the gas coin:
13
+
14
+ ```typescript
15
+ const tx = new Transaction();
16
+
17
+ const [coin] = tx.splitCoins(tx.gas, [100]);
18
+
19
+ tx.transferObjects([coin], recipient);
20
+ ```
21
+
22
+ This approach works well for SUI, but can't be used for other coin types. The CoinWithBalance intent
23
+ solves this by providing a helper function that automatically adds the correct SplitCoins and
24
+ MergeCoins commands to the transaction:
25
+
26
+ ```typescript
27
+ const tx = new Transaction();
28
+
29
+ // Setting the sender is required for the CoinWithBalance intent to resolve coins when not using the gas coin
30
+ tx.setSender(keypair.toSuiAddress());
31
+
32
+ tx.transferObjects(
33
+ [
34
+ // Create a SUI coin (balance is in MIST)
35
+ coinWithBalance({ balance: 100 }),
36
+ // Create a coin of another type
37
+ coinWithBalance({ balance: 100, type: '0x123::foo:Bar' }),
38
+ ],
39
+ recipient,
40
+ );
41
+ ```
42
+
43
+ Splitting the gas coin also causes problems for sponsored transactions. When sponsoring
44
+ transactions, the gas coin comes from the sponsor instead of the transaction sender. Transaction
45
+ sponsors usually do not sponsor transactions that use the gas coin for anything other than gas. To
46
+ transfer SUI that does not use the gas coin, you can set the `useGasCoin` option to `false`:
47
+
48
+ ```typescript
49
+ const tx = new Transaction();
50
+ tx.transferObjects([coinWithBalance({ balance: 100, useGasCoin: false })], recipient);
51
+ ```
52
+
53
+ It's important to only set `useGasCoin` option to false for sponsored transactions, otherwise the
54
+ coinWithBalance intent may use all the SUI coins, leaving no coins to use for gas.
55
+
56
+ ## How it works
57
+
58
+ When the `CoinWithBalance` intent is resolved, it will look up the senders owned coins for each type
59
+ that needs to be created. It will then find a set of coins with sufficient balance to cover the
60
+ desired balance, to combine them into a single coin. This coin is then used in a `SplitCoins`
61
+ command to create the desired coin.
@@ -0,0 +1,71 @@
1
+ # Building Offline
2
+
3
+ > Build transactions without a network connection
4
+
5
+ To build a transaction offline (with no `client` required), you need to fully define all of your
6
+ inputs, gas configuration, and expiration.
7
+
8
+ ## Required Configuration
9
+
10
+ When building offline, you must set the following:
11
+
12
+ - **Sender address** - The address that will execute the transaction
13
+ - **Gas price** - The price per gas unit (can be obtained from the network beforehand)
14
+ - **Gas budget** - The maximum gas to spend on this transaction
15
+ - **Gas payment** - One or more coin object references to use for gas, or an empty array for Address
16
+ Balances
17
+ - **Expiration** - Only needed when using address balances for gas
18
+
19
+ ```tsx
20
+ const { referenceGasPrice } = await client.getReferenceGasPrice();
21
+
22
+ const tx = new Transaction();
23
+
24
+ tx.setSender('0x<your-address>');
25
+ tx.setGasPrice(referenceGasPrice);
26
+ tx.setGasBudget(50_000_000);
27
+ tx.setGasPayment([
28
+ {
29
+ objectId: '0x<gas-coin-object-id>',
30
+ version: '<object-version>',
31
+ digest: '<object-digest>',
32
+ },
33
+ ]);
34
+
35
+ // Build the transaction without a client
36
+ const bytes = await tx.build();
37
+ ```
38
+
39
+ ## Object References
40
+
41
+ For objects used in your transaction, you must provide full object references using the `Inputs`
42
+ helper:
43
+
44
+ ```tsx
45
+ // For owned or immutable objects
46
+ tx.object(
47
+ Inputs.ObjectRef({
48
+ objectId: '0x<object-id>',
49
+ version: '<object-version>',
50
+ digest: '<object-digest>',
51
+ }),
52
+ );
53
+
54
+ // For shared objects
55
+ tx.object(
56
+ Inputs.SharedObjectRef({
57
+ objectId: '0x<object-id>',
58
+ initialSharedVersion: '<initial-shared-version>',
59
+ mutable: true,
60
+ }),
61
+ );
62
+
63
+ // For receiving objects (objects being received by another object)
64
+ tx.object(
65
+ Inputs.ReceivingRef({
66
+ objectId: '0x<object-id>',
67
+ version: '<object-version>',
68
+ digest: '<object-digest>',
69
+ }),
70
+ );
71
+ ```
@@ -0,0 +1,22 @@
1
+ # Sponsored Transactions
2
+
3
+ > Pay gas fees on behalf of other users with sponsored transactions
4
+
5
+ The transaction builder can support sponsored transactions by using the `onlyTransactionKind` flag
6
+ when building the transaction.
7
+
8
+ ```tsx
9
+ const tx = new Transaction();
10
+
11
+ // ... add some transactions...
12
+
13
+ const kindBytes = await tx.build({ provider, onlyTransactionKind: true });
14
+
15
+ // construct a sponsored transaction from the kind bytes
16
+ const sponsoredtx = Transaction.fromKind(kindBytes);
17
+
18
+ // you can now set the sponsored transaction data that is required
19
+ sponsoredtx.setSender(sender);
20
+ sponsoredtx.setGasOwner(sponsor);
21
+ sponsoredtx.setGasPayment(sponsorCoins);
22
+ ```
@@ -0,0 +1,59 @@
1
+ # Derived Objects
2
+
3
+ > Compute derived object IDs from parent objects
4
+
5
+ Derived objects enable deterministic IDs for objects, enabling offline derivation of object IDs.
6
+ [Click here to read more.](https://docs.sui.io/concepts/sui-move-concepts/derived-objects)
7
+
8
+ To derive an object ID, you can import `deriveObjectID` function exposed from utils.
9
+
10
+ ```typescript
11
+
12
+ ```
13
+
14
+ To derive any object, you need to have its parent's ID (the object from which it was derived), and
15
+ the key used to generate it.
16
+
17
+ > **Warning:** It is recommended to verify the on-chain `derived_object::derive_address` match your
18
+ > off-chain calculation (at least once when implementing offline calculations), especially for
19
+ > critical cases like transferring assets.
20
+
21
+ ## Deriving using primitive keys
22
+
23
+ To derive the IDs using primitive types, you can use the built-in types like this, assuming you have
24
+ a parent object with ID `0xc0ffee`.
25
+
26
+ ```typescript
27
+ // Example 1: On-chain derivation for `0xc0ffee + vector<u8>([0,1,2])
28
+ deriveObjectID('0xc0ffee', 'vector<u8>', bcs.vector(bcs.u8()).serialize([0, 1, 2]).toBytes());
29
+
30
+ // Example 2: On-chain derivation for `0xc0ffee + address('0x111')`
31
+ deriveObjectID('0xc0ffee', 'address', bcs.Address.serialize('0x111').toBytes());
32
+
33
+ // Example 3: On-chain derivation for `0xc0ffee + non-ascii string ("foo")`
34
+ deriveObjectID('0xc0ffee', '0x1::string::String', bcs.String.serialize('foo').toBytes());
35
+ ```
36
+
37
+ ## Deriving using custom types
38
+
39
+ To derive IDs using your custom objects, you can use BCS & the known type IDs.
40
+
41
+ Assuming a custom struct on-chain (for the key) being:
42
+
43
+ ```move
44
+ public struct DemoStruct has copy, store, drop { value: u64 }
45
+ ```
46
+
47
+ you can derive it by doing:
48
+
49
+ ```typescript
50
+ // Assuming we wanted to derive for key `DemoStruct { value: 1 }`.
51
+ const bcsType = bcs.struct('DemoStruct', {
52
+ value: bcs.u64(),
53
+ });
54
+
55
+ const key = bcsType.serialize({ value: 1 }).toBytes();
56
+
57
+ // Derive the object ID for the key `DemoStruct { value: 1 }`.
58
+ deriveObjectID('0xc0ffee', `0xc0ffee::demo::DemoStruct`, key);
59
+ ```
@@ -0,0 +1,52 @@
1
+ # The `@mysten/sui/utils` package
2
+
3
+ > Utility functions for addresses, coins, and common operations
4
+
5
+ This package contains some utilities that simplify common operations when working with the Sui
6
+ TypeScript SDK.
7
+
8
+ ## Constants
9
+
10
+ A set of constants exported for common uses cases:
11
+
12
+ - `MIST_PER_SUI`: The conversion rate for MIST to SUI (1,000,000,000)
13
+ - `SUI_DECIMALS`: the number of decimals you must shift a MIST value to convert it to SUI (`9`)
14
+ - `SUI_ADDRESS_LENGTH`: The number of bytes in a Sui address (32)
15
+ - `MOVE_STDLIB_ADDRESS`: The address for the Sui Move standard library
16
+ - `SUI_FRAMEWORK_ADDRESS`: The address for the Sui Framework
17
+ - `SUI_SYSTEM_ADDRESS`: The address for the Sui System module
18
+ - `SUI_CLOCK_OBJECT_ID`: The address for the `sui::clock::Clock` object
19
+ - `SUI_SYSTEM_STATE_OBJECT_ID`: The address for the `SuiSystemState` object
20
+ - `SUI_RANDOM_OBJECT_ID`: The address for the `0x2::random::Random` object
21
+
22
+ ## Formatters
23
+
24
+ You can use the following helpers to format various values:
25
+
26
+ - `formatAddress`
27
+ - `formatDigest`
28
+ - `normalizeStructTag`
29
+ - `normalizeSuiAddress`
30
+ - `normalizeSuiObjectId`
31
+ - `normalizeSuiNSName`
32
+ - `normalizeSuiNSName`
33
+
34
+ ## Validators
35
+
36
+ You can use the following helpers to validate the format of various values (this only validates that
37
+ the value is in the correct format, but does not validate the value is valid for a specific use
38
+ case, or exists on chain).
39
+
40
+ - `isValidSuiAddress`
41
+ - `isValidSuiObjectId`
42
+ - `isValidTransactionDigest`
43
+ - `isValidSuiNSName`
44
+
45
+ ## Encoding
46
+
47
+ The following methods are re-exported to help with converting between commonly used encodings
48
+
49
+ - `fromHex`: Deserializes a hex string to a Uint8Array
50
+ - `toHex`: Serializes a Uint8Array to a hex string
51
+ - `fromBase64`: Deserializes a base64 string to a Uint8Array
52
+ - `toBase64`: Serializes a Uint8Array to a base64 string