@mysten/docs 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +24 -0
  2. package/dist/bcs/index.md +358 -0
  3. package/dist/bcs/llms-index.md +4 -0
  4. package/dist/codegen/index.md +441 -0
  5. package/dist/codegen/llms-index.md +4 -0
  6. package/dist/dapp-kit/actions/connect-wallet.md +69 -0
  7. package/dist/dapp-kit/actions/disconnect-wallet.md +38 -0
  8. package/dist/dapp-kit/actions/sign-and-execute-transaction.md +96 -0
  9. package/dist/dapp-kit/actions/sign-personal-message.md +58 -0
  10. package/dist/dapp-kit/actions/sign-transaction.md +65 -0
  11. package/dist/dapp-kit/actions/switch-account.md +37 -0
  12. package/dist/dapp-kit/actions/switch-network.md +37 -0
  13. package/dist/dapp-kit/dapp-kit-instance.md +162 -0
  14. package/dist/dapp-kit/getting-started/create-dapp.md +151 -0
  15. package/dist/dapp-kit/getting-started/next-js.md +162 -0
  16. package/dist/dapp-kit/getting-started/react.md +172 -0
  17. package/dist/dapp-kit/getting-started/vue.md +193 -0
  18. package/dist/dapp-kit/index.md +70 -0
  19. package/dist/dapp-kit/llms-index.md +26 -0
  20. package/dist/dapp-kit/react/components/connect-button.md +42 -0
  21. package/dist/dapp-kit/react/components/connect-modal.md +51 -0
  22. package/dist/dapp-kit/react/components/index.md +13 -0
  23. package/dist/dapp-kit/react/dapp-kit-provider.md +86 -0
  24. package/dist/dapp-kit/react/hooks/index.md +25 -0
  25. package/dist/dapp-kit/react/hooks/use-current-account.md +33 -0
  26. package/dist/dapp-kit/react/hooks/use-current-client.md +36 -0
  27. package/dist/dapp-kit/react/hooks/use-current-network.md +28 -0
  28. package/dist/dapp-kit/react/hooks/use-current-wallet.md +36 -0
  29. package/dist/dapp-kit/react/hooks/use-dapp-kit.md +100 -0
  30. package/dist/dapp-kit/react/hooks/use-wallet-connection.md +48 -0
  31. package/dist/dapp-kit/react/hooks/use-wallets.md +33 -0
  32. package/dist/dapp-kit/state.md +169 -0
  33. package/dist/dapp-kit/theming.md +196 -0
  34. package/dist/dapp-kit/web-components/connect-button.md +89 -0
  35. package/dist/dapp-kit/web-components/connect-modal.md +177 -0
  36. package/dist/kiosk/advanced-examples.md +101 -0
  37. package/dist/kiosk/from-v1.md +320 -0
  38. package/dist/kiosk/index.md +22 -0
  39. package/dist/kiosk/kiosk-client/introduction.md +52 -0
  40. package/dist/kiosk/kiosk-client/kiosk-transaction/examples.md +119 -0
  41. package/dist/kiosk/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
  42. package/dist/kiosk/kiosk-client/kiosk-transaction/managing.md +235 -0
  43. package/dist/kiosk/kiosk-client/kiosk-transaction/purchasing.md +110 -0
  44. package/dist/kiosk/kiosk-client/querying.md +237 -0
  45. package/dist/kiosk/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
  46. package/dist/kiosk/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
  47. package/dist/kiosk/llms-index.md +8 -0
  48. package/dist/llms-index.md +125 -0
  49. package/dist/payment-kit/getting-started.md +256 -0
  50. package/dist/payment-kit/index.md +132 -0
  51. package/dist/payment-kit/llms-index.md +8 -0
  52. package/dist/payment-kit/payment-kit-sdk.md +747 -0
  53. package/dist/payment-kit/payment-processing.md +372 -0
  54. package/dist/payment-kit/registry-management.md +529 -0
  55. package/dist/seal/index.md +85 -0
  56. package/dist/seal/llms-index.md +4 -0
  57. package/dist/slush-wallet/dapp.md +95 -0
  58. package/dist/slush-wallet/deep-linking.md +465 -0
  59. package/dist/slush-wallet/index.md +7 -0
  60. package/dist/slush-wallet/llms-index.md +6 -0
  61. package/dist/sui/bcs.md +134 -0
  62. package/dist/sui/clients/core.md +606 -0
  63. package/dist/sui/clients/graphql.md +101 -0
  64. package/dist/sui/clients/grpc.md +155 -0
  65. package/dist/sui/clients/index.md +95 -0
  66. package/dist/sui/clients/json-rpc.md +239 -0
  67. package/dist/sui/cryptography/keypairs.md +267 -0
  68. package/dist/sui/cryptography/multisig.md +194 -0
  69. package/dist/sui/cryptography/passkey.md +111 -0
  70. package/dist/sui/cryptography/webcrypto-signer.md +81 -0
  71. package/dist/sui/executors.md +148 -0
  72. package/dist/sui/faucet.md +26 -0
  73. package/dist/sui/hello-sui.md +115 -0
  74. package/dist/sui/index.md +53 -0
  75. package/dist/sui/install.md +61 -0
  76. package/dist/sui/llm-docs.md +32 -0
  77. package/dist/sui/llms-index.md +44 -0
  78. package/dist/sui/migrations/0.38.md +58 -0
  79. package/dist/sui/migrations/sui-1.0.md +455 -0
  80. package/dist/sui/migrations/sui-2.0/agent-prompt.md +42 -0
  81. package/dist/sui/migrations/sui-2.0/dapp-kit.md +350 -0
  82. package/dist/sui/migrations/sui-2.0/deepbook-v3.md +33 -0
  83. package/dist/sui/migrations/sui-2.0/index.md +158 -0
  84. package/dist/sui/migrations/sui-2.0/json-rpc-migration.md +386 -0
  85. package/dist/sui/migrations/sui-2.0/kiosk.md +120 -0
  86. package/dist/sui/migrations/sui-2.0/sdk-maintainers.md +90 -0
  87. package/dist/sui/migrations/sui-2.0/seal.md +14 -0
  88. package/dist/sui/migrations/sui-2.0/sui.md +341 -0
  89. package/dist/sui/migrations/sui-2.0/suins.md +43 -0
  90. package/dist/sui/migrations/sui-2.0/wallet-builders.md +66 -0
  91. package/dist/sui/migrations/sui-2.0/walrus.md +41 -0
  92. package/dist/sui/migrations/sui-2.0/zksend.md +95 -0
  93. package/dist/sui/plugins.md +258 -0
  94. package/dist/sui/sdk-building.md +344 -0
  95. package/dist/sui/transaction-building/basics.md +299 -0
  96. package/dist/sui/transaction-building/gas.md +62 -0
  97. package/dist/sui/transaction-building/intents.md +62 -0
  98. package/dist/sui/transaction-building/offline.md +73 -0
  99. package/dist/sui/transaction-building/sponsored-transactions.md +22 -0
  100. package/dist/sui/utils/derived_objects.md +59 -0
  101. package/dist/sui/utils/index.md +52 -0
  102. package/dist/sui/zklogin.md +83 -0
  103. package/dist/walrus/index.md +527 -0
  104. package/dist/walrus/llms-index.md +4 -0
  105. package/dist/zksend/index.md +27 -0
  106. package/dist/zksend/link-builder.md +192 -0
  107. package/dist/zksend/llms-index.md +5 -0
  108. package/package.json +66 -0
@@ -0,0 +1,52 @@
1
+ # Kiosk Client
2
+
3
+ > Introduction to the KioskClient for querying and managing kiosks
4
+
5
+ The Kiosk SDK exports a client extension that provides all Kiosk functionality.
6
+
7
+ > We recommend you keep only one client instance throughout your dApp or script. For example, in
8
+ > React, you'd use a context to provide the client.
9
+
10
+ > **Note:** The Kiosk SDK requires `SuiJsonRpcClient` or `SuiGraphQLClient`. It does not work with
11
+ > `SuiGrpcClient` because it uses event queries that are not available in gRPC.
12
+
13
+ ## Setting up the kiosk extension
14
+
15
+ Add the kiosk extension to your Sui client using `$extend()`. The extension currently supports
16
+ `mainnet` and `testnet`. See the next section for usage on other networks.
17
+
18
+ _Mysten Kiosk rules and extensions are not supported in Devnet due to network wipes (that would
19
+ require constantly changing the package IDs)._
20
+
21
+ ```typescript
22
+
23
+ const client = new SuiJsonRpcClient({
24
+ url: getJsonRpcFullnodeUrl('testnet'),
25
+ network: 'testnet',
26
+ }).$extend(kiosk());
27
+
28
+ // Now you can use client.kiosk for all kiosk operations
29
+ const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0x...' });
30
+ ```
31
+
32
+ ### Using the kiosk extension on devnet or localnet
33
+
34
+ To use all the functionality of Kiosk SDK outside of `mainnet` and `testnet`, pass the `packageIds`
35
+ for the rules and extensions you want to use.
36
+
37
+ ```typescript
38
+
39
+ const client = new SuiJsonRpcClient({
40
+ url: getJsonRpcFullnodeUrl('devnet'),
41
+ network: 'devnet',
42
+ }).$extend(
43
+ kiosk({
44
+ packageIds: {
45
+ kioskLockRulePackageId: '0x...',
46
+ royaltyRulePackageId: '0x...',
47
+ personalKioskRulePackageId: '0x...',
48
+ floorPriceRulePackageId: '0x...',
49
+ },
50
+ }),
51
+ );
52
+ ```
@@ -0,0 +1,119 @@
1
+ # Examples
2
+
3
+ > Kiosk transaction code examples
4
+
5
+ The following dApp-focused examples demonstrate how to use the SDK to interact with Kiosk.
6
+
7
+ ## Minting into Kiosk example
8
+
9
+ For every scenario using Kiosk in dApps, the user who has connected their wallet either has at least
10
+ one kiosk already or you must create it for them.
11
+
12
+ The SDK supports the scenario of `silently` creating the kiosk, as part of our Programmable
13
+ Transaction.
14
+
15
+ Assume that the mint function of the contract is:
16
+
17
+ `public fun mint(coin: Coin<SUI>, kiosk: &mut Kiosk, cap: &KioskOwnerCap){...}`
18
+
19
+ ### When the user has a kiosk
20
+
21
+ ```typescript
22
+ const connectedAddress = '0xAnAddress';
23
+
24
+ // This function should run when the user connects the wallet.
25
+ // We should re-use the same client instance throughout our dApp.
26
+ const getCap = async () => {
27
+ let { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: connectedAddress });
28
+ // Assume that the user has only 1 kiosk.
29
+ // Here, you need to do some more checks in a realistic scenario.
30
+ // And possibly give the user in our dApp a kiosk selector to choose which one they want to interact with (if they own more than one).
31
+ return kioskOwnerCaps[0];
32
+ };
33
+
34
+ // The mint function could be like the following.
35
+ const mint = async () => {
36
+ const tx = new Transaction();
37
+ const kioskTx = new KioskTransaction({
38
+ kioskClient: client.kiosk,
39
+ transaction: tx,
40
+ cap: await getCap(),
41
+ });
42
+
43
+ // Assume it costs one SUI
44
+ let coin = tx.splitCoins(tx.gas, [1_000_000_000]);
45
+
46
+ // A function that mints directly into the kiosk.
47
+ tx.moveCall({
48
+ target: '0xMyGame::hero::mint',
49
+ arguments: [
50
+ coin, // the payment
51
+ kioskTx.getKiosk(), // our kiosk that the hero will be placed in.
52
+ kioskTx.getKioskCap(), // our kiosk cap, so that the function can place or lock it.
53
+ ],
54
+ });
55
+
56
+ kioskTx.finalize();
57
+
58
+ // Sign and execute transaction.
59
+ await signAndExecuteTransaction({ tx: tx });
60
+ };
61
+ ```
62
+
63
+ ### When the user doesn't have a kiosk (silent creation)
64
+
65
+ ```typescript
66
+ // Our mint function.
67
+ const mint = async () => {
68
+ const tx = new Transaction();
69
+ const kioskTx = new KioskTransaction({ kioskClient: client.kiosk, transaction: tx });
70
+
71
+ // Creates a kiosk.
72
+ kioskTx.create();
73
+
74
+ // We'll assume it costs 1 SUI
75
+ let coin = tx.splitCoins(tx.gas, [1_000_000_000]);
76
+
77
+ // A function that mints directly into the kiosk.
78
+ tx.moveCall({
79
+ target: '0xMyGame::hero::mint',
80
+ arguments: [
81
+ coin, // the payment
82
+ kioskTx.getKiosk(), // our kiosk that the hero will be placed in.
83
+ kioskTx.getKioskCap(), // our kiosk cap, so that the function can place or lock it.
84
+ ],
85
+ });
86
+
87
+ kioskTx.shareAndTransferCap('0xAddressToTransferCapTo');
88
+ kioskTx.finalize();
89
+
90
+ // Sign and execute transaction.
91
+ await signAndExecuteTransaction({ tx: tx });
92
+ };
93
+ ```
94
+
95
+ ## Borrowing an item from kiosk to do an action
96
+
97
+ ```typescript
98
+ // A sample function that borrows an item from kiosk and levels it up.
99
+ const levelUp = async (object) => {
100
+ const tx = new Transaction();
101
+
102
+ new KioskTransaction({ kioskClient: client.kiosk, transaction: tx, cap })
103
+ .borrowTx(object, (item) => {
104
+ tx.moveCall({
105
+ target: '0xMyGame::hero::level_up',
106
+ arguments: [item],
107
+ });
108
+ })
109
+ .finalize();
110
+
111
+ // Sign and execute transaction.
112
+ await signAndExecuteTransaction({ tx: tx });
113
+ };
114
+
115
+ levelUp({
116
+ itemType: '0x2MyGame::hero::Hero',
117
+ itemId: '0xMyHeroObjectId',
118
+ });
119
+ ```
@@ -0,0 +1,103 @@
1
+ # KioskTransaction
2
+
3
+ > Build kiosk transactions for listing, purchasing, and managing items
4
+
5
+ `KioskTransaction` is the client to build transactions that involve Kiosk. It's used similar to
6
+ `Transaction`, and helps in building a transaction.
7
+
8
+ You need to instantiate it once in every Programmable Transaction Block (PTB) that you're building.
9
+
10
+ There are two flows to follow, the first being managing an existing kiosk, and the second is
11
+ creating a new one. It hides all the complexity between a personal and a non-personal kiosk.
12
+
13
+ ## Using an existing kiosk
14
+
15
+ If you have already retrieved a kiosk from `client.kiosk.getOwnedKiosks()`, you can pass a cap.
16
+
17
+ > You must always call `kioskTx.finalize()` before signing and executing the transaction, as your
18
+ > last command.
19
+
20
+ ```typescript
21
+ const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0xMyAddress' });
22
+
23
+ const tx = new Transaction();
24
+ const kioskTx = new KioskTransaction({
25
+ transaction: tx,
26
+ kioskClient: client.kiosk,
27
+ cap: kioskOwnerCaps[0],
28
+ });
29
+
30
+ // Now you can do whatever you want with kioskTx.
31
+ // For example, you could withdraw the profits from the kiosk.
32
+ kioskTx.withdraw('0xMyAddress', 100_000_000n);
33
+
34
+ // You could also chain some other functionality if you want to.
35
+ kioskTx
36
+ .place({
37
+ itemType: '0xMyItemType',
38
+ item: '0xMyItem',
39
+ })
40
+ .list({
41
+ itemType: '0xMyItemType',
42
+ itemId: '0xMyItem',
43
+ price: 10000n,
44
+ });
45
+
46
+ // Always called as our last kioskTx interaction.
47
+ kioskTx.finalize();
48
+
49
+ // Sign and execute transaction.
50
+ await signAndExecuteTransaction({ tx: tx });
51
+ ```
52
+
53
+ ## Creating a new kiosk
54
+
55
+ If you don't have a kiosk yet, you can create one using `create()`. The `KioskTransaction` enables
56
+ use of the newly created kiosk to execute some functionality in the same PTB.
57
+
58
+ ```typescript
59
+ const tx = new Transaction();
60
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk });
61
+
62
+ // Calls the creation function.
63
+ kioskTx.create();
64
+
65
+ // We can use the kiosk for some action.
66
+ // For example, placing an item in the newly created kiosk.
67
+ kioskTx.place({
68
+ itemType: '0x...::hero::Hero',
69
+ item: '0xAHero',
70
+ });
71
+
72
+ // Shares the kiosk and transfers the `KioskOwnerCap` to the owner.
73
+ kioskTx.shareAndTransferCap('0xMyAddress');
74
+
75
+ // Always called as our last kioskTx interaction.
76
+ kioskTx.finalize();
77
+
78
+ // Sign and execute transaction.
79
+ await signAndExecuteTransaction({ tx: tx });
80
+ ```
81
+
82
+ ## Creating a new personal kiosk
83
+
84
+ `KioskTransaction` makes it easy to create a new personal kiosk, and use it in the same PTB.
85
+
86
+ ```typescript
87
+ const tx = new Transaction();
88
+ const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk });
89
+
90
+ // An example that creates a personal kiosk, uses it to place an item, and shares it.
91
+ // The `PersonalKioskCap` is automatically transferred to the sender when calling `.finalize()`.
92
+ // The `Kiosk` is automatically shared when calling `.finalize()`.
93
+ kioskTx
94
+ .createPersonal(true) // `true` allows us to reuse the kiosk in the same PTB. If we pass false, we can only call `kioskTx.finalize()`.
95
+ .place({
96
+ itemType: '0x...::hero::Hero',
97
+ item: '0xAHero',
98
+ })
99
+ .finalize(); // finalize is always our last call.
100
+
101
+ // Sign and execute transaction.
102
+ await signAndExecuteTransaction({ tx: tx });
103
+ ```
@@ -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
+ ```