@mysten/kiosk 1.2.5 → 1.3.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.
@@ -0,0 +1,237 @@
1
+ # Querying
2
+
3
+ > Query kiosk contents, owned kiosks, items, and transfer policies using the Kiosk SDK.
4
+
5
+ You can use `client.kiosk` to query kiosk data. It helps you get owned kiosks for an address, as
6
+ well as fetching all the contents of a specified kiosk.
7
+
8
+ ## Querying owned kiosks
9
+
10
+ Querying owned kiosks returns a list of `kioskOwnerCaps`, as well as a list of the `kioskIds`.
11
+
12
+ `KioskOwnerCap` is important in this case, as it is used for managing an owned kiosk, as well as
13
+ purchasing.
14
+
15
+ ```typescript
16
+ const address = '0xAddress';
17
+ // You can perform actions, like querying the owned kiosks for an address.
18
+ const { kioskOwnerCaps, kioskIds } = await client.kiosk.getOwnedKiosks({ address });
19
+ console.log(kioskOwnerCaps);
20
+
21
+ /**
22
+ * An example response for an address that owns two kiosks (one of which is personal)
23
+ [
24
+ {
25
+ isPersonal: true,
26
+ digest: '9mstxLa87E3VEewQ62EEQDKb7ZH2irrEXeMetQjQHzXz',
27
+ version: '18',
28
+ objectId: '0x5d4df1b8da5e1b6bafbb4b7dc5c73e532324d82c86e331f71bf1ea5dff18dccc',
29
+ kioskId: '0x8453fc71611ce8ff73efcca42ed241dcaf7dc65411b56a7be42e6a0bc3d72c13'
30
+ },
31
+ {
32
+ isPersonal: false,
33
+ digest: '8fsKgCh5c2ycPKMVUqUz2H6D9WkPjRHmGP454z67afJh',
34
+ version: '15',
35
+ objectId: '0x84f5a9a1379d73eceae03d0578637936e208daa809e04ec07a8085c798a980fd',
36
+ kioskId: '0xf8c826aae52bc576768032ce496b7fc349f9003603ed1541c8033fc5c2dd2d2c'
37
+ }
38
+ ]
39
+ */
40
+ ```
41
+
42
+ ## Querying kiosk content
43
+
44
+ You can follow the sample to query a kiosk's contents. We recommend saving the `items` structure
45
+ (`KioskItem`), as it's useful when you're trying to purchase from one.
46
+
47
+ `listing` field only applies on items that are listed for sale.
48
+
49
+ ```typescript
50
+ const id = `0xKioskId`;
51
+
52
+ // You can perform actions, like querying a kiosk's contents.
53
+ const res = await client.kiosk.getKiosk({
54
+ id,
55
+ options: {
56
+ withKioskFields: true, // this flag also returns the `kiosk` object in the response, which includes the base setup
57
+ withListingPrices: true, // This flag enables / disables the fetching of the listing prices.
58
+ },
59
+ });
60
+ console.log(res);
61
+ /**
62
+ * An example response of an existing kiosk
63
+ *
64
+ {
65
+ items: [
66
+ {
67
+ objectId: '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537',
68
+ type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
69
+ isLocked: false,
70
+ kioskId: '0x6d45df1942c11048a9182e3f732262e6e3c95ddd2e5f338c565f531717c2617f',
71
+ listing: undefined,
72
+ data: {
73
+ objectId: '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537',
74
+ version: '18',
75
+ digest: 'As9fkLEP4QVChhYuGemB185xyyzWG4hspSa3UZ6TWR8b',
76
+ display: { data: null, error: null },
77
+ content: {
78
+ dataType: 'moveObject',
79
+ type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
80
+ hasPublicTransfer: true,
81
+ fields: {
82
+ id: {
83
+ id: '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537'
84
+ },
85
+ level: 3
86
+ }
87
+ }
88
+ }
89
+ },
90
+ {
91
+ objectId: '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372',
92
+ type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
93
+ isLocked: true,
94
+ kioskId: '0x6d45df1942c11048a9182e3f732262e6e3c95ddd2e5f338c565f531717c2617f',
95
+ listing: undefined,
96
+ data: {
97
+ objectId: '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372',
98
+ version: '15',
99
+ digest: 'J1MdmHUCXJEKd86rkmMwWASMV86wGkVS9P6SFPyRaKVV',
100
+ display: { data: null, error: null },
101
+ content: {
102
+ dataType: 'moveObject',
103
+ type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
104
+ hasPublicTransfer: true,
105
+ fields: {
106
+ id: {
107
+ id: '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372'
108
+ },
109
+ level: 1
110
+ }
111
+ }
112
+ }
113
+ }
114
+ ],
115
+ itemIds: [
116
+ '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537',
117
+ '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372'
118
+ ],
119
+ listingIds: [],
120
+ extensions: [],
121
+ kiosk: {
122
+ id: '6d45df1942c11048a9182e3f732262e6e3c95ddd2e5f338c565f531717c2617f',
123
+ profits: '100000',
124
+ owner: '96300f8d9064f954f99db2d7fbe2ad0c5e4344f0e22392330285d399498cfaf3',
125
+ itemCount: 2,
126
+ allowExtensions: false
127
+ }
128
+ }
129
+ */
130
+ ```
131
+
132
+ ## Query kiosk extension
133
+
134
+ Queries an extension's data. Returns `null` if there's no extension with that type installed.
135
+
136
+ ```typescript
137
+ // The type of the custom extension.
138
+ const type = '0xAddress::custom_extension::ACustomExtensionType';
139
+
140
+ const extension = await client.kiosk.getKioskExtension({
141
+ kioskId: '0xAKioskId',
142
+ type,
143
+ });
144
+
145
+ console.log(extension);
146
+
147
+ /**
148
+ * An example output of the response
149
+ {
150
+ objectId: 'extensionObjectId',
151
+ type: '0xAddress::custom_extension::ACustomExtensionType',
152
+ isEnabled: true,
153
+ permissions: "3",
154
+ storageId: '0xExampleStorageId',
155
+ storageSize: "0",
156
+ }
157
+ */
158
+ ```
159
+
160
+ ## Querying transfer policy for type
161
+
162
+ ```typescript
163
+ const itemType = '0xAddress::hero::Hero';
164
+ // You can perform actions, like querying transfer policy for type.
165
+ const policies = await client.kiosk.getTransferPolicies({ type: itemType });
166
+ console.log(policies);
167
+
168
+ /* An example output of the response
169
+ [
170
+ {
171
+ id: '0x074847055fe4ea9a7f51eeaf095c05875509403059115af121cfea9b8de355de',
172
+ type: '0x2::transfer_policy::TransferPolicy<0x85926b03d56e49bedfca558fc6a2540d43bdfb5c218190d63b571f33afe255f8::hero::Hero>',
173
+ owner: { Shared: { initial_shared_version: 5 } },
174
+ rules: [
175
+ 'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::kiosk_lock_rule::Rule',
176
+ 'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::floor_price_rule::Rule',
177
+ 'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::royalty_rule::Rule',
178
+ 'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::personal_kiosk_rule::Rule'
179
+ ],
180
+ balance: '20000'
181
+ }
182
+ ]
183
+ */
184
+ ```
185
+
186
+ ## Get owned transfer policies
187
+
188
+ Queries to find all the owned transfer policies. Useful to manage transfer policies, and can be
189
+ combined with `TransferPolicyTransaction` to easily add or remove rules and withdraw profits.
190
+
191
+ ```typescript
192
+ // The address that owns the transfer policies.
193
+ const address = '0xAddress';
194
+ // You can perform actions, like querying the owned transfer policies for an address.
195
+ const policies = await client.kiosk.getOwnedTransferPolicies({ address });
196
+ console.log(policies);
197
+
198
+ /**
199
+ * An example output of the response
200
+ [
201
+ {
202
+ policyId: '0x6b6eca8df6e70ea6447e639ef26b519039b5e9123642258eea1b3c781e94faca',
203
+ policyCapId: '0x34a4794d4ad6578ac345d23ca0f7a4632ca88de297daaf24a1cdbc91e1547be4',
204
+ type: '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Hero'
205
+ },
206
+ {
207
+ policyId: '0x87ac2dd80011ed2de9c7916a19145ff520959acd3d8c3dbd100aa74b34155a0a',
208
+ policyCapId: '0x858edda13c5c9086b2491eafed39e0ea58511268bb90d90464a2d7b5ed3f3880',
209
+ type: '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Villain'
210
+ }
211
+ ]
212
+ */
213
+ ```
214
+
215
+ ## Get owned transfer policies by type
216
+
217
+ Queries to find all the owned transfer policies for a specific type. Useful to manage transfer
218
+ policies, and can be combined with
219
+
220
+ ```typescript
221
+ // The address that owns the transfer policies.
222
+ const address = '0xAddress';
223
+ // The type of the transfer policy.
224
+ const type = '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Hero';
225
+
226
+ // We can query by type.
227
+ const policies = await client.kiosk.getOwnedTransferPoliciesByType({ address, type });
228
+
229
+ // An example output of the response
230
+ // [
231
+ // {
232
+ // policyId: '0x6b6eca8df6e70ea6447e639ef26b519039b5e9123642258eea1b3c781e94faca',
233
+ // policyCapId: '0x34a4794d4ad6578ac345d23ca0f7a4632ca88de297daaf24a1cdbc91e1547be4',
234
+ // type: '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Hero'
235
+ // }
236
+ // ]
237
+ ```
@@ -0,0 +1,79 @@
1
+ # TransferPolicyTransaction
2
+
3
+ > Create and manage transfer policies for kiosk items using the Kiosk SDK.
4
+
5
+ `TransferPolicyTransaction` is the client to build transactions that involve transfer policy
6
+ management. It's used similar to `KioskTransaction`, and helps in crafting transactions to manage a
7
+ transfer policy.
8
+
9
+ You need to instantiate it once in every Programmable Transaction Block (PTB) that you're building.
10
+
11
+ Similar to `KioskTransaction`, you can either create a new transfer policy, or use an existing one.
12
+
13
+ ## Using an existing transfer policy
14
+
15
+ If you have already retrieved a transfer policy from `client.kiosk.getOwnedTransferPolicies()`, or
16
+ `client.kiosk.getOwnedTransferPoliciesByType()`, you can pass a `TransferPolicyCap` result when
17
+ instantiating.
18
+
19
+ ```typescript
20
+ // You could have more than one cap, since we can create more than one transfer policy.
21
+ const heroPolicyCaps = await client.kiosk.getOwnedTransferPoliciesByType({
22
+ type: `${packageId}::hero::Hero`,
23
+ address: '0xConnectedAddress',
24
+ });
25
+
26
+ const tx = new Transaction();
27
+ // You can choose to use any of the caps you have. For this example, use the first one.
28
+ const tpTx = new TransferPolicyTransaction({
29
+ kioskClient: client.kiosk,
30
+ transaction: tx,
31
+ cap: heroPolicyCaps[0],
32
+ });
33
+
34
+ // A demonstration of using all the available rule add/remove functions.
35
+ // You can chain these commands.
36
+ tpTx
37
+ .addFloorPriceRule(10n)
38
+ .addLockRule()
39
+ .addRoyaltyRule(percentageToBasisPoints(10), 0)
40
+ .addPersonalKioskRule();
41
+ // .removeFloorPriceRule()
42
+ // .removeLockRule()
43
+ // .removeRoyaltyRule()
44
+ // .removePersonalKioskRule()
45
+
46
+ // Sign and execute transaction.
47
+ await signAndExecuteTransaction({ tx: tx });
48
+ ```
49
+
50
+ ## Creating a new transfer policy
51
+
52
+ If you don't have an existing transfer policy, you can create a new one. You can also attach rules
53
+ in the same PTB.
54
+
55
+ ```typescript
56
+ const publisher = '0xPackagePublisherObject';
57
+ const tx = new Transaction();
58
+
59
+ const tpTx = new TransferPolicyTransaction({ kioskClient: client.kiosk, transaction: tx });
60
+
61
+ // This is an async call, as the SDK protects from accidentally creating
62
+ // a second transfer policy.
63
+ // You can skip this check by passing `skipCheck: true`.
64
+ await tpTx.create({
65
+ type: `${heroPackageId}::hero::Hero`,
66
+ publisher,
67
+ });
68
+
69
+ tpTx
70
+ .addLockRule()
71
+ .addFloorPriceRule(1000n)
72
+ .addRoyaltyRule(percentageToBasisPoints(10), 100)
73
+ .addPersonalKioskRule()
74
+ // Transfers the `TransferPolicyCap` to the user and shares the transfer policy.
75
+ .shareAndTransferCap('address_to_transfer_cap_to');
76
+
77
+ // Sign and execute transaction.
78
+ await signAndExecuteTransaction({ tx: tx });
79
+ ```
@@ -0,0 +1,113 @@
1
+ # Using the manager
2
+
3
+ > Use the TransferPolicyTransaction manager to add rules and withdraw profits.
4
+
5
+ After following the introduction steps on how to initialize a transfer policy transaction you can
6
+ call any of the available functions to prepare your Programmable Transaction Block (PTB).
7
+
8
+ ## Available functions
9
+
10
+ ### Withdraw profits
11
+
12
+ `withdraw(address: string, amount?: string | bigint)`
13
+
14
+ After setting up the manager, you can withdraw profits from the specified transfer policy.
15
+
16
+ `amount` is optional. Leave empty to withdraw all profits.
17
+
18
+ ```typescript
19
+ // ... tp transaction is initialized and policy is set.
20
+ // Withdraw 10 SUI from the policy. Leave last parameter empty to withdraw all profits.
21
+ tpTx.withdraw('address_to_transfer_coin', 10_000_000_000n);
22
+ ```
23
+
24
+ ### Add/Remove rules
25
+
26
+ > You can chain the actions when you're calling them, to add multiple rules.
27
+
28
+ After setting up the transaction, you can add any of the supported rules to the policy.
29
+
30
+ #### Royalty rule
31
+
32
+ `addRoyaltyRule(percentageBps: number | string, minAmount: number | string)`
33
+
34
+ You can add the royalty rule like the following example.
35
+
36
+ `percentageToBasisPoints` is a helper to convert a percentage (0.00-100%) to basis points.
37
+
38
+ Use `minAmount` to set a minimum amount per transaction, so that the royalty paid is
39
+ **MAX(percentageBps, minAmount)**. Use 0 for no minimum amount.
40
+
41
+ ```typescript
42
+ // ... tp transaction is initialized and policy is set.
43
+ tpTx.addRoyaltyRule(percentageToBasisPoints(30), 1_000_000_000);
44
+ ```
45
+
46
+ You can remove the rule by calling:
47
+
48
+ ```typescript
49
+ tpTx.removeRoyaltyRule();
50
+ ```
51
+
52
+ #### Kiosk lock rule
53
+
54
+ `addLockRule()`
55
+
56
+ You can add the kiosk lock rule like the following example.
57
+
58
+ ```typescript
59
+ // ... tp transaction is initialized and policy is set.
60
+ tpTx.addLockRule();
61
+ ```
62
+
63
+ You can remove the rule by calling:
64
+
65
+ ```typescript
66
+ tpTx.removeLockRule();
67
+ ```
68
+
69
+ #### Personal kiosk rule
70
+
71
+ `addPersonalKioskRule()`
72
+
73
+ You can add the kiosk lock rule like the following example.
74
+
75
+ ```typescript
76
+ // ... tp transaction is initialized and policy is set.
77
+ tpTx.addPersonalKioskRule();
78
+ ```
79
+
80
+ You can remove the rule by calling:
81
+
82
+ ```typescript
83
+ tpTx.removePersonalKioskRule();
84
+ ```
85
+
86
+ #### Floor price rule
87
+
88
+ `addFloorPriceRule(minPrice: string | bigint)`
89
+
90
+ You can add the floor price rule like the following example:
91
+
92
+ ```typescript
93
+ // ... tp transaction is initialized and policy is set.
94
+ tpTx.addFloorPriceRule(10_000_000_000n); // sets 10 SUI as the floor price.
95
+ ```
96
+
97
+ You can remove the rule by calling:
98
+
99
+ ```typescript
100
+ tpTx.removeFloorPriceRule();
101
+ ```
102
+
103
+ #### Updating rules
104
+
105
+ If you want to update a rule, call the `remove...` function, and then call `add` again with the new
106
+ settings.
107
+
108
+ Example:
109
+
110
+ ```typescript
111
+ // ... tp transaction is initialized and policy is set.
112
+ tpTx.removeRoyaltyRule().addRoyaltyRule(percentageToBasisPoints(20), 1_000_000_000);
113
+ ```
@@ -0,0 +1,14 @@
1
+ # Kiosk
2
+ > Interact with on-chain commerce applications
3
+
4
+ - [Kiosk SDK](..md): TypeScript SDK for interacting with Sui Kiosk onchain commerce.
5
+ - [Kiosk Client](./kiosk-client/introduction.md): Introduction to the KioskClient extension for querying and managing kiosks on Sui.
6
+ - [Querying](./kiosk-client/querying.md): Query kiosk contents, owned kiosks, items, and transfer policies using the Kiosk SDK.
7
+ - [KioskTransaction](./kiosk-client/kiosk-transaction/kiosk-transaction.md): Build kiosk transactions for listing, purchasing, and managing items on Sui.
8
+ - [Managing Owned Kiosk](./kiosk-client/kiosk-transaction/managing.md): Manage kiosk items by placing, listing, delisting, and withdrawing using the Kiosk SDK.
9
+ - [Purchasing from a kiosk](./kiosk-client/kiosk-transaction/purchasing.md): Purchase items from kiosks with automatic transfer policy rule resolution.
10
+ - [Examples](./kiosk-client/kiosk-transaction/examples.md): Practical code examples for kiosk transactions including minting, listing, and purchasing.
11
+ - [TransferPolicyTransaction](./kiosk-client/transfer-policy-transaction/introduction.md): Create and manage transfer policies for kiosk items using the Kiosk SDK.
12
+ - [Using the manager](./kiosk-client/transfer-policy-transaction/using-the-manager.md): Use the TransferPolicyTransaction manager to add rules and withdraw profits.
13
+ - [Advanced Examples](./advanced-examples.md): Advanced Kiosk SDK usage patterns and code examples for complex scenarios.
14
+ - [Migrating from Kiosk SDK V1](./from-v1.md): Migrate from Kiosk SDK v1 to the current version with the builder-pattern API.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@mysten/kiosk",
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui Kiosk library",
5
- "version": "1.2.5",
5
+ "version": "1.3.0",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",
8
8
  "main": "./dist/index.mjs",
@@ -32,20 +32,20 @@
32
32
  "url": "https://github.com/MystenLabs/ts-sdks/issues/new"
33
33
  },
34
34
  "dependencies": {
35
- "@mysten/bcs": "^2.0.4",
36
- "@mysten/utils": "^0.3.2"
35
+ "@mysten/bcs": "^2.1.0",
36
+ "@mysten/utils": "^0.4.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "cross-env": "^10.1.0",
40
- "tmp": "^0.2.5",
40
+ "tmp": "^0.2.7",
41
41
  "ts-retry-promise": "^0.8.1",
42
- "typescript": "^5.9.3",
43
- "vite": "^8.0.5",
44
- "vitest": "^4.0.17",
45
- "wait-on": "^9.0.3"
42
+ "typescript": "^6.0.3",
43
+ "vite": "^8.0.16",
44
+ "vitest": "^4.1.8",
45
+ "wait-on": "^9.0.10"
46
46
  },
47
47
  "peerDependencies": {
48
- "@mysten/sui": "^2.16.1"
48
+ "@mysten/sui": "^2.18.0"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rm -rf dist && tsc --noEmit && tsdown",
@@ -7,7 +7,7 @@ import {
7
7
  BcsEnum,
8
8
  BcsTuple,
9
9
  } from '@mysten/sui/bcs';
10
- import { normalizeSuiAddress } from '@mysten/sui/utils';
10
+ import { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';
11
11
  import { type TransactionArgument, isArgument } from '@mysten/sui/transactions';
12
12
  import { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';
13
13
 
@@ -157,10 +157,143 @@ export function normalizeMoveArguments(
157
157
  return normalizedArgs;
158
158
  }
159
159
 
160
+ /* -------------------------- Move type tags -------------------------- */
161
+
162
+ /** A type argument: a type tag string, or a BCS type whose name is a Move type. */
163
+ export type TypeArgument = string | BcsType<any>;
164
+
165
+ export interface TypeTagOptions {
166
+ package?: string;
167
+ typeArguments?: readonly TypeArgument[];
168
+ }
169
+
170
+ /**
171
+ * `typeArguments` is required when the type's name contains unfilled
172
+ * `phantom X` parameters (at any depth). Everything else — argument arity,
173
+ * position contents, and tag validity — is validated at runtime.
174
+ */
175
+ type TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`
176
+ ? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]
177
+ : [options?: TypeTagOptions];
178
+
179
+ type ResolveTypeTagOptions<Name extends string> = {
180
+ client: ClientWithCoreApi;
181
+ } & (Name extends `${string}phantom ${string}`
182
+ ? TypeTagOptions & { typeArguments: readonly TypeArgument[] }
183
+ : TypeTagOptions);
184
+
185
+ const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
186
+
187
+ function splitTopLevelTypeArgs(inner: string): string[] {
188
+ const parts: string[] = [];
189
+ let depth = 0;
190
+ let current = '';
191
+ for (const char of inner) {
192
+ if (char === ',' && depth === 0) {
193
+ parts.push(current.trim());
194
+ current = '';
195
+ continue;
196
+ }
197
+ if (char === '<') depth++;
198
+ if (char === '>') depth--;
199
+ current += char;
200
+ }
201
+ if (current) parts.push(current.trim());
202
+ return parts;
203
+ }
204
+
205
+ function buildTypeTag(name: string, options: TypeTagOptions | undefined): string {
206
+ const lt = name.indexOf('<');
207
+ const base = lt === -1 ? name : name.slice(0, lt);
208
+
209
+ if (base.split('::').length !== 3) {
210
+ throw new Error(`${name} is not a top-level Move type`);
211
+ }
212
+
213
+ let result = name;
214
+
215
+ if (options?.typeArguments) {
216
+ const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
217
+ const supplied = options.typeArguments.map((arg) => {
218
+ if (typeof arg === 'string') {
219
+ return arg;
220
+ }
221
+ if (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {
222
+ return arg.name;
223
+ }
224
+ throw new Error(`Invalid type argument ${stringify(arg)}`);
225
+ });
226
+
227
+ if (supplied.length !== baked.length) {
228
+ throw new Error(
229
+ `Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,
230
+ );
231
+ }
232
+
233
+ result = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;
234
+ }
235
+
236
+ if (HAS_PHANTOM_REGEX.test(result)) {
237
+ throw new Error(
238
+ options?.typeArguments
239
+ ? `A type argument contains an unfilled phantom parameter in ${result}`
240
+ : `Missing type arguments for ${result}`,
241
+ );
242
+ }
243
+
244
+ if (options?.package) {
245
+ const [, ...rest] = result.split('::');
246
+ result = [options.package, ...rest].join('::');
247
+ }
248
+
249
+ // fully validate address-only tags (MVR names can't be parsed as type tags)
250
+ if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {
251
+ TypeTagSerializer.parseFromStr(result);
252
+ }
253
+
254
+ return result;
255
+ }
256
+
257
+ async function resolveBuiltTypeTag(
258
+ name: string,
259
+ options: { client: ClientWithCoreApi } & TypeTagOptions,
260
+ ): Promise<string> {
261
+ const { client, ...rest } = options;
262
+ const { type } = await client.core.mvr.resolveType({
263
+ type: buildTypeTag(name, rest),
264
+ });
265
+ return normalizeStructTag(type);
266
+ }
267
+
160
268
  export class MoveStruct<
161
269
  T extends Record<string, BcsType<any>>,
162
270
  const Name extends string = string,
163
271
  > extends BcsStruct<T, Name> {
272
+ /**
273
+ * Build the type tag for this struct.
274
+ *
275
+ * `typeArguments` is the full positional list, in Move declaration order, and
276
+ * is required when the struct has unfilled phantom parameters. The result may
277
+ * contain MVR names: those are valid in transaction `typeArguments`, but for
278
+ * queries or comparisons against on-chain data use `resolveTypeTag` instead.
279
+ */
280
+ typeTag(...args: TypeTagParams<Name>): string {
281
+ return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
282
+ }
283
+
284
+ /**
285
+ * Build the type tag for this struct, then resolve any MVR names through the
286
+ * client (using its configured overrides and the MVR API) and return the
287
+ * normalized, address-only form suitable for queries and comparisons against
288
+ * on-chain data.
289
+ */
290
+ async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
291
+ return resolveBuiltTypeTag(
292
+ this.name,
293
+ options as { client: ClientWithCoreApi } & TypeTagOptions,
294
+ );
295
+ }
296
+
164
297
  async get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
165
298
  objectId,
166
299
  ...options
@@ -215,16 +348,44 @@ export class MoveStruct<
215
348
  export class MoveEnum<
216
349
  T extends Record<string, BcsType<any> | null>,
217
350
  const Name extends string,
218
- > extends BcsEnum<T, Name> {}
351
+ > extends BcsEnum<T, Name> {
352
+ /** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */
353
+ typeTag(...args: TypeTagParams<Name>): string {
354
+ return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
355
+ }
356
+
357
+ /** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */
358
+ async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
359
+ return resolveBuiltTypeTag(
360
+ this.name,
361
+ options as { client: ClientWithCoreApi } & TypeTagOptions,
362
+ );
363
+ }
364
+ }
219
365
 
220
366
  export class MoveTuple<
221
367
  const T extends readonly BcsType<any>[],
222
368
  const Name extends string,
223
- > extends BcsTuple<T, Name> {}
369
+ > extends BcsTuple<T, Name> {
370
+ /** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */
371
+ typeTag(...args: TypeTagParams<Name>): string {
372
+ return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
373
+ }
374
+
375
+ /** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */
376
+ async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
377
+ return resolveBuiltTypeTag(
378
+ this.name,
379
+ options as { client: ClientWithCoreApi } & TypeTagOptions,
380
+ );
381
+ }
382
+ }
224
383
 
225
384
  function stringify(val: unknown) {
226
385
  if (typeof val === 'object') {
227
- return JSON.stringify(val, (val: unknown) => val);
386
+ return JSON.stringify(val, (_key, value) =>
387
+ typeof value === 'bigint' ? value.toString() : value,
388
+ );
228
389
  }
229
390
  if (typeof val === 'bigint') {
230
391
  return val.toString();