@mysten/kiosk 1.1.2 → 1.2.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 (33) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/client/kiosk-client.d.mts.map +1 -1
  3. package/dist/client/kiosk-transaction.d.mts +1 -2
  4. package/dist/client/kiosk-transaction.d.mts.map +1 -1
  5. package/dist/client/tp-transaction.d.mts +1 -2
  6. package/dist/client/tp-transaction.d.mts.map +1 -1
  7. package/dist/constants.d.mts.map +1 -1
  8. package/dist/query/client-utils.mjs.map +1 -1
  9. package/dist/types/index.d.mts +0 -1
  10. package/dist/types/index.d.mts.map +1 -1
  11. package/dist/types/kiosk.d.mts +14 -28
  12. package/dist/types/kiosk.d.mts.map +1 -1
  13. package/dist/types/kiosk.mjs.map +1 -1
  14. package/dist/types/transfer-policy.d.mts.map +1 -1
  15. package/dist/utils.d.mts +1 -1
  16. package/dist/utils.d.mts.map +1 -1
  17. package/dist/utils.mjs.map +1 -1
  18. package/docs/advanced-examples.md +100 -0
  19. package/docs/from-v1.md +314 -0
  20. package/docs/index.md +22 -0
  21. package/docs/kiosk-client/introduction.md +50 -0
  22. package/docs/kiosk-client/kiosk-transaction/examples.md +119 -0
  23. package/docs/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
  24. package/docs/kiosk-client/kiosk-transaction/managing.md +235 -0
  25. package/docs/kiosk-client/kiosk-transaction/purchasing.md +110 -0
  26. package/docs/kiosk-client/querying.md +237 -0
  27. package/docs/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
  28. package/docs/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
  29. package/docs/llms-index.md +10 -0
  30. package/package.json +7 -5
  31. package/src/query/client-utils.ts +1 -1
  32. package/src/types/kiosk.ts +8 -5
  33. package/src/utils.ts +1 -1
@@ -0,0 +1,235 @@
1
+ # Managing Owned Kiosk
2
+
3
+ > Manage kiosk items: place, list, delist, and withdraw
4
+
5
+ The kiosk extension (`client.kiosk`) helps in managing a kiosk.
6
+
7
+ You need to follow the steps explained in the [Kiosk Transaction section](#kiosk-transaction) to
8
+ create a `KioskTransaction`.
9
+
10
+ ## Available functions
11
+
12
+ ### take
13
+
14
+ Removes an item from the Kiosk and returns a `TransactionArgument` to use it in a different
15
+ Programmable Transaction Block (PTB) call.
16
+
17
+ ```typescript
18
+ const itemId = '0xHeroAddress';
19
+ const itemType = '0x..::hero::Hero';
20
+
21
+ const tx = new Transaction();
22
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
23
+
24
+ // Take item from kiosk.
25
+ const item = kioskTx.take({
26
+ itemId,
27
+ itemType,
28
+ });
29
+
30
+ // Do something with `item`, like transfer it to someone else.
31
+ tx.transferObjects([item], 'address_to_transfer_the_object');
32
+
33
+ // Finalize the kiosk Tx.
34
+ kioskTx.finalize();
35
+
36
+ // Sign and execute transaction.
37
+ await signAndExecuteTransaction({ tx: tx });
38
+ ```
39
+
40
+ ### transfer
41
+
42
+ Similar to `take`, but transfers the item to an address internally.
43
+
44
+ ```typescript
45
+ const itemId = '0xHeroAddress';
46
+ const itemType = '0x..::hero::Hero';
47
+
48
+ const tx = new Transaction();
49
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
50
+
51
+ // Take item from kiosk.
52
+ kioskTx
53
+ .transfer({
54
+ itemId,
55
+ itemType,
56
+ address: 'address_to_transfer_the_object',
57
+ })
58
+ .finalize();
59
+
60
+ // Sign and execute transaction.
61
+ await signAndExecuteTransaction({ tx: tx });
62
+ ```
63
+
64
+ ### place
65
+
66
+ Places an item in the kiosk.
67
+
68
+ ```typescript
69
+ const item = '0xHeroAddress';
70
+ const itemType = '0x..::hero::Hero';
71
+
72
+ const tx = new Transaction();
73
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
74
+
75
+ kioskTx
76
+ .place({
77
+ item,
78
+ itemType,
79
+ })
80
+ .finalize();
81
+
82
+ // Sign and execute transaction.
83
+ await signAndExecuteTransaction({ tx: tx });
84
+ ```
85
+
86
+ ### list
87
+
88
+ Lists an item for sale (the item must be in the kiosk).
89
+
90
+ ```typescript
91
+ const itemId = '0xHeroAddress';
92
+ const itemType = '0x..::hero::Hero';
93
+
94
+ const tx = new Transaction();
95
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
96
+
97
+ kioskTx
98
+ .list({
99
+ itemId,
100
+ itemType,
101
+ price: 100000n,
102
+ })
103
+ .finalize();
104
+
105
+ // Sign and execute transaction.
106
+ await signAndExecuteTransaction({ tx: tx });
107
+ ```
108
+
109
+ ### placeAndList
110
+
111
+ List an item for sale by first placing it in the kiosk (places the item and lists it for sale). It's
112
+ a short hand for `place()` and `list()`.
113
+
114
+ ```typescript
115
+ const item = '0xHeroAddress';
116
+ const itemType = '0x..::hero::Hero';
117
+
118
+ const tx = new Transaction();
119
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
120
+
121
+ kioskTx
122
+ .placeAndList({
123
+ item,
124
+ itemType,
125
+ price: 100000n,
126
+ })
127
+ .finalize();
128
+
129
+ // Sign and execute transaction.
130
+ await signAndExecuteTransaction({ tx: tx });
131
+ ```
132
+
133
+ ### delist
134
+
135
+ Removes the listing, keeping the item placed in the kiosk.
136
+
137
+ ```typescript
138
+ const itemId = '0xHeroAddress';
139
+ const itemType = '0x..::hero::Hero';
140
+
141
+ const tx = new Transaction();
142
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
143
+
144
+ kioskTx
145
+ .delist({
146
+ itemId,
147
+ itemType,
148
+ })
149
+ .finalize();
150
+
151
+ // sign and execute transaction.
152
+ await signAndExecuteTransaction({ tx: tx });
153
+ ```
154
+
155
+ ### withdraw
156
+
157
+ Withdraw (all or specific amount) from a kiosk.
158
+
159
+ `amount`: Can be empty, which will withdraw all the funds.
160
+
161
+ ```typescript
162
+ const tx = new Transaction();
163
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
164
+
165
+ kioskTx.withdraw('address_to_transfer_funds', 100000n).finalize();
166
+
167
+ // Sign and execute transaction.
168
+ await signAndExecuteTransaction({ tx: tx });
169
+ ```
170
+
171
+ ### borrowTx (callback)
172
+
173
+ Borrows an item from a kiosk. This function follows the `callback` approach, similar to the
174
+ ownerCap. The return of the item happens automatically after the execution of the callback.
175
+
176
+ ```typescript
177
+ const itemId = '0xHeroAddress';
178
+ const itemType = '0x..::hero::Hero';
179
+
180
+ const tx = new Transaction();
181
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
182
+
183
+ kioskTx
184
+ .borrowTx(
185
+ {
186
+ itemId,
187
+ itemType,
188
+ },
189
+ (item) => {
190
+ tx.moveCall({
191
+ target: '0xMyGame::hero::level_up',
192
+ arguments: [item],
193
+ });
194
+ },
195
+ )
196
+ .finalize();
197
+
198
+ // Sign and execute transaction.
199
+ await signAndExecuteTransaction({ tx: tx });
200
+ ```
201
+
202
+ ### borrow / return
203
+
204
+ Similar to `borrowTx`, borrows an item from the kiosk, but returns two transaction arguments: `item`
205
+ & `promise`. You can use the `item` in your PTBs, but you must always call the `return()` function
206
+ with the `item` and the `Promise`.
207
+
208
+ ```typescript
209
+ const itemId = '0xHeroAddress';
210
+ const itemType = '0x..::hero::Hero';
211
+
212
+ const tx = new Transaction();
213
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
214
+
215
+ const [item, promise] = kioskTx.borrow({
216
+ itemId,
217
+ itemType,
218
+ });
219
+
220
+ tx.moveCall({
221
+ target: '0xMyGame::hero::level_up',
222
+ arguments: [item],
223
+ });
224
+
225
+ kioskTx
226
+ .return({
227
+ itemType,
228
+ item,
229
+ promise,
230
+ })
231
+ .finalize();
232
+
233
+ // Sign and execute transaction.
234
+ await signAndExecuteTransaction({ tx: tx });
235
+ ```
@@ -0,0 +1,110 @@
1
+ # Purchasing from a kiosk
2
+
3
+ > Purchase items from kiosks with transfer policy resolution
4
+
5
+ One of the base functionalities of the SDK is a seamless purchasing flow, allowing for ease of rules
6
+ resolving (hiding away the calls). The SDK supports all four rules by default, and works for
7
+ `TESTNET` and `MAINNET`. To support other networks,
8
+ [follow the instructions in the Introduction](../introduction#using-kioskclient-on-devnet-or-localnet).
9
+
10
+ ## How to purchase
11
+
12
+ By default, the SDK places the item in the caller's kiosk, unless there's a lock rule, in which case
13
+ it locks it.
14
+
15
+ Then following is an example of a purchase call.
16
+
17
+ ```typescript
18
+ const item = {
19
+ itemType: '0x..::hero::Hero',
20
+ itemId: '0x..',
21
+ price: 100000n,
22
+ sellerKiosk: '0xSellerKiosk',
23
+ };
24
+
25
+ const tx = new Transaction();
26
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
27
+
28
+ await kioskTx.purchaseAndResolve({
29
+ itemType: item.itemType,
30
+ itemId: item.itemId,
31
+ price: item.price,
32
+ sellerKiosk: item.sellerKiosk,
33
+ });
34
+
35
+ kioskTx.finalize();
36
+
37
+ // Sign and execute transaction.
38
+ await signAndExecuteTransaction({ tx: tx });
39
+ ```
40
+
41
+ > The function queries for a TransferPolicy for that item, and if a policy is found, it
42
+ > automatically resolves all the rules, one by one. You can add a custom rule resolver to the kiosk
43
+ > extension, with instructions on how to resolve a custom rule. Read more in the next section.
44
+
45
+ ## Supporting a custom rule
46
+
47
+ You can use the `purchaseAndResolve` function to support a custom rule.
48
+
49
+ ```typescript
50
+ // Assuming client is set up with .$extend(kiosk())
51
+ const myCustomRule = {
52
+ rule: `0xMyRuleAddress::game_rule::Rule`,
53
+ packageId: `0xMyRuleAddress`,
54
+ // The resolving function. This is called when calling the `purchaseAndResolve`.
55
+ resolveRuleFunction: (params: RuleResolvingParams) => {
56
+ // By knowing the params we have here, we can extract the variables we need to resolve this rule.
57
+ const { transaction, itemType, packageId, extraArgs, transferRequest } = params;
58
+ const { gamePass } = extraArgs;
59
+ if (!gamePass) throw new Error('GamePass not supplied');
60
+
61
+ // Calls the game's rule prove function, which could, for example
62
+ // allow rules to resolve only if the holder has a gamePass object.
63
+ transaction.moveCall({
64
+ target: `${packageId}::game_rule::prove_pass`,
65
+ typeArguments: [itemType],
66
+ arguments: [transferRequest, transaction.object(gamePass)],
67
+ });
68
+ },
69
+ };
70
+ // This allows rules resolution from the `purchaseAndResolve` function.
71
+ client.kiosk.addRuleResolver(myCustomRule);
72
+
73
+ // Assume `cap` is obtained from client.kiosk.getOwnedKiosks()
74
+ const tx = new Transaction();
75
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
76
+
77
+ await kioskTx.purchaseAndResolve({
78
+ itemType: item.itemType,
79
+ itemId: item.itemId,
80
+ price: item.price,
81
+ sellerKiosk: item.sellerKiosk,
82
+ extraArgs: {
83
+ gamePass: '0xMyGamePassObjectId',
84
+ },
85
+ });
86
+
87
+ kioskTx.finalize();
88
+
89
+ // Sign and execute transaction.
90
+ await signAndExecuteTransaction({ tx: tx });
91
+ ```
92
+
93
+ ```typescript
94
+ // For reference, here's the RuleResolvingParams contents.
95
+ type RuleResolvingParams = {
96
+ transaction: Transaction;
97
+ itemType: string;
98
+ itemId: string;
99
+ price: string;
100
+ policyId: ObjectArgument;
101
+ sellerKiosk: ObjectArgument;
102
+ kiosk: ObjectArgument;
103
+ kioskCap: ObjectArgument;
104
+ transferRequest: TransactionObjectArgument;
105
+ purchasedItem: TransactionObjectArgument;
106
+ packageId: string;
107
+ extraArgs: Record<string, any>; // extraParams contains more possible {key, values} to pass for custom rules.
108
+ kioskClient: KioskClient; // This is the client.kiosk extension
109
+ };
110
+ ```
@@ -0,0 +1,237 @@
1
+ # Querying
2
+
3
+ > Query kiosk contents, items, and transfer policies
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
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
+ ```