@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.
- package/README.md +24 -0
- package/dist/bcs/index.md +358 -0
- package/dist/bcs/llms-index.md +4 -0
- package/dist/codegen/index.md +441 -0
- package/dist/codegen/llms-index.md +4 -0
- package/dist/dapp-kit/actions/connect-wallet.md +69 -0
- package/dist/dapp-kit/actions/disconnect-wallet.md +38 -0
- package/dist/dapp-kit/actions/sign-and-execute-transaction.md +96 -0
- package/dist/dapp-kit/actions/sign-personal-message.md +58 -0
- package/dist/dapp-kit/actions/sign-transaction.md +65 -0
- package/dist/dapp-kit/actions/switch-account.md +37 -0
- package/dist/dapp-kit/actions/switch-network.md +37 -0
- package/dist/dapp-kit/dapp-kit-instance.md +162 -0
- package/dist/dapp-kit/getting-started/create-dapp.md +151 -0
- package/dist/dapp-kit/getting-started/next-js.md +162 -0
- package/dist/dapp-kit/getting-started/react.md +172 -0
- package/dist/dapp-kit/getting-started/vue.md +193 -0
- package/dist/dapp-kit/index.md +70 -0
- package/dist/dapp-kit/llms-index.md +26 -0
- package/dist/dapp-kit/react/components/connect-button.md +42 -0
- package/dist/dapp-kit/react/components/connect-modal.md +51 -0
- package/dist/dapp-kit/react/components/index.md +13 -0
- package/dist/dapp-kit/react/dapp-kit-provider.md +86 -0
- package/dist/dapp-kit/react/hooks/index.md +25 -0
- package/dist/dapp-kit/react/hooks/use-current-account.md +33 -0
- package/dist/dapp-kit/react/hooks/use-current-client.md +36 -0
- package/dist/dapp-kit/react/hooks/use-current-network.md +28 -0
- package/dist/dapp-kit/react/hooks/use-current-wallet.md +36 -0
- package/dist/dapp-kit/react/hooks/use-dapp-kit.md +100 -0
- package/dist/dapp-kit/react/hooks/use-wallet-connection.md +48 -0
- package/dist/dapp-kit/react/hooks/use-wallets.md +33 -0
- package/dist/dapp-kit/state.md +169 -0
- package/dist/dapp-kit/theming.md +196 -0
- package/dist/dapp-kit/web-components/connect-button.md +89 -0
- package/dist/dapp-kit/web-components/connect-modal.md +177 -0
- package/dist/kiosk/advanced-examples.md +101 -0
- package/dist/kiosk/from-v1.md +320 -0
- package/dist/kiosk/index.md +22 -0
- package/dist/kiosk/kiosk-client/introduction.md +52 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/examples.md +119 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/managing.md +235 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/purchasing.md +110 -0
- package/dist/kiosk/kiosk-client/querying.md +237 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
- package/dist/kiosk/llms-index.md +8 -0
- package/dist/llms-index.md +125 -0
- package/dist/payment-kit/getting-started.md +256 -0
- package/dist/payment-kit/index.md +132 -0
- package/dist/payment-kit/llms-index.md +8 -0
- package/dist/payment-kit/payment-kit-sdk.md +747 -0
- package/dist/payment-kit/payment-processing.md +372 -0
- package/dist/payment-kit/registry-management.md +529 -0
- package/dist/seal/index.md +85 -0
- package/dist/seal/llms-index.md +4 -0
- package/dist/slush-wallet/dapp.md +95 -0
- package/dist/slush-wallet/deep-linking.md +465 -0
- package/dist/slush-wallet/index.md +7 -0
- package/dist/slush-wallet/llms-index.md +6 -0
- package/dist/sui/bcs.md +134 -0
- package/dist/sui/clients/core.md +606 -0
- package/dist/sui/clients/graphql.md +101 -0
- package/dist/sui/clients/grpc.md +155 -0
- package/dist/sui/clients/index.md +95 -0
- package/dist/sui/clients/json-rpc.md +239 -0
- package/dist/sui/cryptography/keypairs.md +267 -0
- package/dist/sui/cryptography/multisig.md +194 -0
- package/dist/sui/cryptography/passkey.md +111 -0
- package/dist/sui/cryptography/webcrypto-signer.md +81 -0
- package/dist/sui/executors.md +148 -0
- package/dist/sui/faucet.md +26 -0
- package/dist/sui/hello-sui.md +115 -0
- package/dist/sui/index.md +53 -0
- package/dist/sui/install.md +61 -0
- package/dist/sui/llm-docs.md +32 -0
- package/dist/sui/llms-index.md +44 -0
- package/dist/sui/migrations/0.38.md +58 -0
- package/dist/sui/migrations/sui-1.0.md +455 -0
- package/dist/sui/migrations/sui-2.0/agent-prompt.md +42 -0
- package/dist/sui/migrations/sui-2.0/dapp-kit.md +350 -0
- package/dist/sui/migrations/sui-2.0/deepbook-v3.md +33 -0
- package/dist/sui/migrations/sui-2.0/index.md +158 -0
- package/dist/sui/migrations/sui-2.0/json-rpc-migration.md +386 -0
- package/dist/sui/migrations/sui-2.0/kiosk.md +120 -0
- package/dist/sui/migrations/sui-2.0/sdk-maintainers.md +90 -0
- package/dist/sui/migrations/sui-2.0/seal.md +14 -0
- package/dist/sui/migrations/sui-2.0/sui.md +341 -0
- package/dist/sui/migrations/sui-2.0/suins.md +43 -0
- package/dist/sui/migrations/sui-2.0/wallet-builders.md +66 -0
- package/dist/sui/migrations/sui-2.0/walrus.md +41 -0
- package/dist/sui/migrations/sui-2.0/zksend.md +95 -0
- package/dist/sui/plugins.md +258 -0
- package/dist/sui/sdk-building.md +344 -0
- package/dist/sui/transaction-building/basics.md +299 -0
- package/dist/sui/transaction-building/gas.md +62 -0
- package/dist/sui/transaction-building/intents.md +62 -0
- package/dist/sui/transaction-building/offline.md +73 -0
- package/dist/sui/transaction-building/sponsored-transactions.md +22 -0
- package/dist/sui/utils/derived_objects.md +59 -0
- package/dist/sui/utils/index.md +52 -0
- package/dist/sui/zklogin.md +83 -0
- package/dist/walrus/index.md +527 -0
- package/dist/walrus/llms-index.md +4 -0
- package/dist/zksend/index.md +27 -0
- package/dist/zksend/link-builder.md +192 -0
- package/dist/zksend/llms-index.md +5 -0
- package/package.json +66 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Connect Button
|
|
2
|
+
|
|
3
|
+
> Framework-agnostic web component for wallet connection
|
|
4
|
+
|
|
5
|
+
The `<mysten-dapp-kit-connect-button>` Web Component provides a complete wallet connection UI. It
|
|
6
|
+
displays a "Connect Wallet" button when no wallet is connected, and shows the connected account with
|
|
7
|
+
a menu when a wallet is active.
|
|
8
|
+
|
|
9
|
+
> Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
|
|
10
|
+
> page reload. This provides a seamless user experience but can be
|
|
11
|
+
> [disabled](../dapp-kit-instance#disabling-auto-connect) if needed.
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
14
|
+
|
|
15
|
+
### Vanilla
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<mysten-dapp-kit-connect-button></mysten-dapp-kit-connect-button>
|
|
19
|
+
|
|
20
|
+
<script>
|
|
21
|
+
const button = document.querySelector('mysten-dapp-kit-connect-button');
|
|
22
|
+
button!.instance = dAppKit;
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Vue
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<script setup>
|
|
30
|
+
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
35
|
+
</template>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### React
|
|
39
|
+
|
|
40
|
+
DApp Kit React bindings provide a [React wrapper](../react/components/connect-button) for the
|
|
41
|
+
button.
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
The connect button component automatically handles:
|
|
46
|
+
|
|
47
|
+
- **Wallet Connection**: Opens a modal to select and connect a wallet
|
|
48
|
+
- **Account Display**: Shows the connected account address
|
|
49
|
+
- **Account Switching**: Provides a menu to switch between multiple accounts when connected
|
|
50
|
+
- **Disconnection**: Includes a disconnect option in the menu
|
|
51
|
+
|
|
52
|
+
## Properties
|
|
53
|
+
|
|
54
|
+
- **instance** - The dApp Kit instance
|
|
55
|
+
- **modalOptions** (optional) - Configuration options for the connect modal
|
|
56
|
+
- `filterFn` - Function to filter available wallets
|
|
57
|
+
- `sortFn` - Function to sort available wallets
|
|
58
|
+
|
|
59
|
+
## Custom Button Text
|
|
60
|
+
|
|
61
|
+
Use the default slot to customize the button text when not connected:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<mysten-dapp-kit-connect-button>
|
|
65
|
+
<span>Sign In</span>
|
|
66
|
+
</mysten-dapp-kit-connect-button>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Modal Integration
|
|
70
|
+
|
|
71
|
+
The connect button automatically manages its own modal. You don't need to add a separate
|
|
72
|
+
`<mysten-dapp-kit-connect-modal>` component when using the connect button.
|
|
73
|
+
|
|
74
|
+
## Connected State
|
|
75
|
+
|
|
76
|
+
When a wallet is connected, the button transforms into an account menu that displays:
|
|
77
|
+
|
|
78
|
+
- Account address (truncated)
|
|
79
|
+
- SUI balance
|
|
80
|
+
- Network indicator
|
|
81
|
+
- Menu options for:
|
|
82
|
+
- Switching accounts (if multiple accounts available)
|
|
83
|
+
- Managing connection
|
|
84
|
+
- Disconnecting
|
|
85
|
+
|
|
86
|
+
## Server-Side Rendering (SSR)
|
|
87
|
+
|
|
88
|
+
The `<mysten-dapp-kit-connect-button>` Web Component can be only client-side rendered, as wallets
|
|
89
|
+
are detected in the browser. For Next.js guide see [here](../getting-started/next-js).
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Connect Modal
|
|
2
|
+
|
|
3
|
+
> Framework-agnostic web component for wallet selection
|
|
4
|
+
|
|
5
|
+
The `<mysten-dapp-kit-connect-modal>` Web Component provides a modal dialog for wallet connection.
|
|
6
|
+
While most apps should use the [`Connect Button`](./connect-button) which includes an integrated
|
|
7
|
+
modal, the standalone modal is useful for advanced scenarios requiring custom trigger mechanisms.
|
|
8
|
+
|
|
9
|
+
## When to Use
|
|
10
|
+
|
|
11
|
+
Use the standalone modal when you need:
|
|
12
|
+
|
|
13
|
+
- **Custom trigger elements** - Menu items, keyboard shortcuts, or other non-button triggers
|
|
14
|
+
- **Complex UI flows** - Integration into existing navigation or custom wallet management interfaces
|
|
15
|
+
- **Programmatic control** - Opening the modal based on application logic or user actions
|
|
16
|
+
- **Multiple triggers** - Different parts of your UI that can open the same modal
|
|
17
|
+
|
|
18
|
+
For standard wallet connection with a button, use the [Connect Button](./connect-button) component
|
|
19
|
+
instead.
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
### Vanilla
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<button id="custom-trigger">Open Wallet Selector</button>
|
|
27
|
+
<mysten-dapp-kit-connect-modal></mysten-dapp-kit-connect-modal>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import { createDAppKit } from '@mysten/dapp-kit-core';
|
|
31
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
32
|
+
|
|
33
|
+
const GRPC_URLS = {
|
|
34
|
+
mainnet: 'https://fullnode.mainnet.sui.io:443',
|
|
35
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const dAppKit = createDAppKit({
|
|
39
|
+
enableBurnerWallet: import.meta.env.DEV,
|
|
40
|
+
networks: ['mainnet', 'testnet'],
|
|
41
|
+
defaultNetwork: 'testnet',
|
|
42
|
+
createClient(network) {
|
|
43
|
+
return new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] });
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const modal = document.querySelector('mysten-dapp-kit-connect-modal');
|
|
48
|
+
modal!.instance = dAppKit;
|
|
49
|
+
|
|
50
|
+
const trigger = document.getElementById('custom-trigger');
|
|
51
|
+
trigger?.addEventListener('click', () => {
|
|
52
|
+
modal!.show();
|
|
53
|
+
});
|
|
54
|
+
</script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Vue
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<script setup lang="ts">
|
|
61
|
+
|
|
62
|
+
const modalRef = ref();
|
|
63
|
+
const isModalOpen = ref(false);
|
|
64
|
+
|
|
65
|
+
const openModal = () => {
|
|
66
|
+
// Using property binding
|
|
67
|
+
isModalOpen.value = true;
|
|
68
|
+
// Or using method
|
|
69
|
+
modalRef.value.show();
|
|
70
|
+
};
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<!-- Custom trigger -->
|
|
75
|
+
<button @click="openModal">Select Wallet</button>
|
|
76
|
+
|
|
77
|
+
<!-- Modal component -->
|
|
78
|
+
<mysten-dapp-kit-connect-modal
|
|
79
|
+
ref="modalRef"
|
|
80
|
+
:instance="dAppKit"
|
|
81
|
+
:open="isModalOpen"
|
|
82
|
+
@closed="isModalOpen = false"
|
|
83
|
+
/>
|
|
84
|
+
</template>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### React
|
|
88
|
+
|
|
89
|
+
DApp Kit React bindings provide a [React wrapper](../react/components/connect-modal) for the modal.
|
|
90
|
+
|
|
91
|
+
## Properties
|
|
92
|
+
|
|
93
|
+
- **instance** - The dApp Kit instance
|
|
94
|
+
- **open** - Boolean to control modal visibility programmatically
|
|
95
|
+
- **filterFn** (optional) - Function to filter available wallets
|
|
96
|
+
- Type: `(wallet: UiWallet, index: number, array: UiWallet[]) => boolean`
|
|
97
|
+
- **sortFn** (optional) - Function to sort available wallets
|
|
98
|
+
- Type: `(a: UiWallet, b: UiWallet) => number`
|
|
99
|
+
|
|
100
|
+
## Methods
|
|
101
|
+
|
|
102
|
+
### show()
|
|
103
|
+
|
|
104
|
+
Opens the modal programmatically:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
const modal = document.querySelector('mysten-dapp-kit-connect-modal');
|
|
108
|
+
await modal?.show();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### close(returnValue: string)
|
|
112
|
+
|
|
113
|
+
Closes the modal with an optional return value:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
const modal = document.querySelector('mysten-dapp-kit-connect-modal');
|
|
117
|
+
await modal?.close('user-cancelled');
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Events
|
|
121
|
+
|
|
122
|
+
The modal fires several events during its lifecycle:
|
|
123
|
+
|
|
124
|
+
- **open** - Fired before the modal opens (cancelable)
|
|
125
|
+
- **opened** - Fired after the modal has fully opened
|
|
126
|
+
- **close** - Fired before the modal closes (cancelable)
|
|
127
|
+
- **closed** - Fired after the modal has fully closed
|
|
128
|
+
- **cancel** - Fired when clicking backdrop or pressing Escape (cancelable)
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
const modal = document.querySelector('mysten-dapp-kit-connect-modal');
|
|
132
|
+
|
|
133
|
+
modal?.addEventListener('open', (event) => {
|
|
134
|
+
console.log('Modal is about to open');
|
|
135
|
+
// Prevent opening if needed
|
|
136
|
+
// event.preventDefault();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
modal?.addEventListener('opened', () => {
|
|
140
|
+
console.log('Modal is now open');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
modal?.addEventListener('closed', () => {
|
|
144
|
+
console.log('Modal has closed');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
modal?.addEventListener('cancel', (event) => {
|
|
148
|
+
console.log('User clicked backdrop or pressed Escape');
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Examples
|
|
153
|
+
|
|
154
|
+
### Programmatic Control
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
const modal = document.querySelector('mysten-dapp-kit-connect-modal');
|
|
158
|
+
modal.instance = dAppKit;
|
|
159
|
+
|
|
160
|
+
// Open modal when user tries to perform an action that requires connection
|
|
161
|
+
async function performAction() {
|
|
162
|
+
const connection = dAppKit.stores.$connection.get();
|
|
163
|
+
|
|
164
|
+
if (!connection.account) {
|
|
165
|
+
await modal.show();
|
|
166
|
+
// Wait for connection or cancellation
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Proceed with action...
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Server-Side Rendering (SSR)
|
|
175
|
+
|
|
176
|
+
The `<mysten-dapp-kit-connect-modal>` Web Component can be only client-side rendered, as wallets are
|
|
177
|
+
detected in the browser. For Next.js guide see [here](../getting-started/next-js).
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Advanced Examples
|
|
2
|
+
|
|
3
|
+
> Advanced Kiosk SDK usage patterns and examples
|
|
4
|
+
|
|
5
|
+
# Some extended examples
|
|
6
|
+
|
|
7
|
+
For these examples, assume you have the following data and functions available:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
|
|
11
|
+
// a constant for bullshark's type.
|
|
12
|
+
const bullsharkType = `${packageId}::suifrens::SuiFren<${packageId}::bullshark::Bullshark>`;
|
|
13
|
+
// a constant for capy's type.
|
|
14
|
+
const capyType = `${packageId}::suifrens::SuiFren<${packageId}::capy::Capy>`;
|
|
15
|
+
|
|
16
|
+
// initialize the client with the kiosk extension.
|
|
17
|
+
const client = new SuiJsonRpcClient({
|
|
18
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
19
|
+
network: 'mainnet',
|
|
20
|
+
}).$extend(kiosk());
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Minting a SuiFren
|
|
24
|
+
|
|
25
|
+
This example demonstrates how to mint a SuiFren.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
async function mintFren(address: string) {
|
|
29
|
+
const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address });
|
|
30
|
+
|
|
31
|
+
// Choose the first kiosk for simplicity. We could have extra logic here (e.g. let the user choose, pick a personal one, etc).
|
|
32
|
+
const cap = kioskOwnerCaps[0];
|
|
33
|
+
|
|
34
|
+
const tx = new Transaction();
|
|
35
|
+
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
|
|
36
|
+
|
|
37
|
+
// We're mixing the logic here. If the cap is undefined, we create a new kiosk.
|
|
38
|
+
if (!cap) kioskTx.create();
|
|
39
|
+
|
|
40
|
+
// Let's mint a capy here into the kiosk (either a new or an existing one).
|
|
41
|
+
tx.moveCall({
|
|
42
|
+
target: `${packageId}::suifrens::mint_app::mint`,
|
|
43
|
+
arguments: [kioskTx.getKiosk(), kioskTx.getKioskCap()],
|
|
44
|
+
typeArguments: [capyType],
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// If we don't have a cap, that means we create a new kiosk for the user in this flow.
|
|
48
|
+
if (!cap) kioskTx.shareAndTransferCap(address);
|
|
49
|
+
|
|
50
|
+
kioskTx.finalize();
|
|
51
|
+
|
|
52
|
+
// sign and execute transaction.
|
|
53
|
+
await signAndExecuteTransaction({ tx: tx });
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Mixing two Suifrens
|
|
58
|
+
|
|
59
|
+
This example demonstrates how to use the Kiosk SDK to mix two `bullsharks`.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// We're mixing two frens.
|
|
63
|
+
async function mixFrens(firstFrenObjectId: string, secondFrenObjectId: string, cap: KioskOwnerCap) {
|
|
64
|
+
const tx = new Transaction();
|
|
65
|
+
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });
|
|
66
|
+
|
|
67
|
+
// borrow both frens.
|
|
68
|
+
const [fren1, promise1] = kioskTx.borrow({
|
|
69
|
+
itemType: bullsharkType,
|
|
70
|
+
itemId: firstFrenObjectId,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const [fren2, promise2] = kioskTx.borrow({
|
|
74
|
+
itemType: bullsharkType,
|
|
75
|
+
itemId: secondFrenObjectId,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Let's call the mix function. We skip any payment related stuff here.
|
|
79
|
+
tx.moveCall({
|
|
80
|
+
target: `${packageId}::mix_app::mix`,
|
|
81
|
+
arguments: [fren1, fren2, kioskTx.getKiosk(), kioskTx.getKioskCap()],
|
|
82
|
+
typeArguments: [bullsharkType],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
kioskTx
|
|
86
|
+
.return({
|
|
87
|
+
itemType: bullsharkType,
|
|
88
|
+
item: fren1,
|
|
89
|
+
promise: promise1,
|
|
90
|
+
})
|
|
91
|
+
.return({
|
|
92
|
+
itemType: bullsharkType,
|
|
93
|
+
item: fren2,
|
|
94
|
+
promise: promise2,
|
|
95
|
+
})
|
|
96
|
+
.finalize();
|
|
97
|
+
|
|
98
|
+
// sign and execute transaction.
|
|
99
|
+
await signAndExecuteTransaction({ tx: tx });
|
|
100
|
+
}
|
|
101
|
+
```
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Migrating from Kiosk SDK V1
|
|
2
|
+
|
|
3
|
+
> Migrate from Kiosk SDK v1 to the current version
|
|
4
|
+
|
|
5
|
+
The original version of Kiosk SDK provided basic experimentation with the Kiosk API. The new version
|
|
6
|
+
of the SDK (0.7+) provides a more robust experience for building kiosk/transfer policy transactions.
|
|
7
|
+
|
|
8
|
+
The new SDK offers a builder-pattern API, which provides better autocomplete capabilities, and also
|
|
9
|
+
makes code more readable.
|
|
10
|
+
|
|
11
|
+
While a one-to-one mapping between the old and new SDK is not possible, the following examples
|
|
12
|
+
should help you get started.
|
|
13
|
+
|
|
14
|
+
> An important benefit of the new SDK is that it works seamlessly with Personal Kiosk, which was not
|
|
15
|
+
> the case with the previous SDK (you would always have to wrap the transaction with `borrow_cap` /
|
|
16
|
+
> `return_cap` calls depending on whether the kiosk is personal or not).
|
|
17
|
+
|
|
18
|
+
## Placing an item to kiosk and listing it for sale
|
|
19
|
+
|
|
20
|
+
The following example is from the original Kiosk SDK V1 documentation.
|
|
21
|
+
|
|
22
|
+
### Before
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
|
|
26
|
+
const placeAndListToKiosk = async () => {
|
|
27
|
+
const kiosk = 'SomeKioskId';
|
|
28
|
+
const kioskCap = 'KioskCapObjectId';
|
|
29
|
+
const itemType = '0xItemAddr::some:ItemType';
|
|
30
|
+
const item = 'SomeItemId';
|
|
31
|
+
const price = '100000';
|
|
32
|
+
|
|
33
|
+
const tx = new Transaction();
|
|
34
|
+
|
|
35
|
+
placeAndList(tx, itemType, kiosk, kioskCap, item, price);
|
|
36
|
+
|
|
37
|
+
// ... continue to sign and execute the transaction
|
|
38
|
+
// ...
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### After
|
|
43
|
+
|
|
44
|
+
Using the new SDK, you can build the same transaction as follows:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
|
|
48
|
+
// You need to do this only once and re-use it in the application.
|
|
49
|
+
const client = new SuiJsonRpcClient({
|
|
50
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
51
|
+
network: 'mainnet',
|
|
52
|
+
}).$extend(kiosk());
|
|
53
|
+
|
|
54
|
+
const placeAndListToKiosk = async () => {
|
|
55
|
+
// Assume you have saved the user's preferred kiosk Cap somewhere in your app's state.
|
|
56
|
+
const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0xSomeAddress' });
|
|
57
|
+
|
|
58
|
+
const tx = new Transaction();
|
|
59
|
+
|
|
60
|
+
// Assume you use the first owned kiosk.
|
|
61
|
+
new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap: kioskOwnerCaps[0] })
|
|
62
|
+
.placeAndList({
|
|
63
|
+
itemType: '0xItemAddr::some:ItemType',
|
|
64
|
+
item: 'SomeItemId',
|
|
65
|
+
price: '100000',
|
|
66
|
+
})
|
|
67
|
+
.finalize();
|
|
68
|
+
|
|
69
|
+
// ... continue to sign and execute the transaction
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Create a new kiosk
|
|
74
|
+
|
|
75
|
+
The following example is from the original Kiosk SDK V1 documentation.
|
|
76
|
+
|
|
77
|
+
### Before
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
|
|
81
|
+
const createKiosk = async () => {
|
|
82
|
+
const accountAddress = '0xSomeSuiAddress';
|
|
83
|
+
|
|
84
|
+
const tx = new Transaction();
|
|
85
|
+
const kiosk_cap = createKioskAndShare(tx);
|
|
86
|
+
|
|
87
|
+
tx.transferObjects([kiosk_cap], accountAddress);
|
|
88
|
+
|
|
89
|
+
// ... continue to sign and execute the transaction
|
|
90
|
+
// ...
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### After
|
|
95
|
+
|
|
96
|
+
Using the new SDK, you can build the same transaction as follows:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
|
|
100
|
+
// You need to do this only once and re-use it in the application.
|
|
101
|
+
const client = new SuiJsonRpcClient({
|
|
102
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
103
|
+
network: 'mainnet',
|
|
104
|
+
}).$extend(kiosk());
|
|
105
|
+
|
|
106
|
+
const createKiosk = async () => {
|
|
107
|
+
const tx = new Transaction();
|
|
108
|
+
|
|
109
|
+
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk });
|
|
110
|
+
|
|
111
|
+
kioskTx.create().shareAndTransferCap('0xSomeSuiAddress').finalize();
|
|
112
|
+
|
|
113
|
+
// ... continue to sign and execute the transaction
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Purchasing an item and resolving rules
|
|
118
|
+
|
|
119
|
+
The following example is from the original Kiosk SDK V1 documentation.
|
|
120
|
+
|
|
121
|
+
### Before
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
|
|
125
|
+
queryTransferPolicy,
|
|
126
|
+
purchaseAndResolvePolicies,
|
|
127
|
+
place,
|
|
128
|
+
testnetEnvironment,
|
|
129
|
+
} from '@mysten/kiosk';
|
|
130
|
+
|
|
131
|
+
const client = new SuiJsonRpcClient({
|
|
132
|
+
url: 'https://fullnode.testnet.sui.io:443',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// The kiosk we're purchasing from.
|
|
136
|
+
const kioskId = `0xSomeKioskAddress`;
|
|
137
|
+
// A sample item retrieved from `fetchKiosk` function (or hard-coded).
|
|
138
|
+
const item = {
|
|
139
|
+
isLocked: false,
|
|
140
|
+
objectId: '0xb892d61a9992a10c9453efcdbd14ca9720d7dc1000a2048224209c9e544ed223',
|
|
141
|
+
type: '0x52852c4ba80040395b259c641e70b702426a58990ff73cecf5afd31954429090::test::TestItem',
|
|
142
|
+
listing: {
|
|
143
|
+
isExclusive: false,
|
|
144
|
+
listingId: '0x368b512ff2514dbea814f26ec9a3d41198c00e8ed778099961e9ed22a9f0032b',
|
|
145
|
+
price: '20000000000', // in MIST
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
const ownedKiosk = `0xMyKioskAddress`;
|
|
149
|
+
const ownedKioskCap = `0xMyKioskOwnerCap`;
|
|
150
|
+
|
|
151
|
+
const purchaseItem = async (item, kioskId) => {
|
|
152
|
+
// Fetch the policy of the item (could be an array, if there's more than one transfer policy)
|
|
153
|
+
const policies = await queryTransferPolicy(client, item.type);
|
|
154
|
+
// Selecting the first one for simplicity.
|
|
155
|
+
const policyId = policy[0]?.id;
|
|
156
|
+
// Initialize transaction.
|
|
157
|
+
const tx = new Transaction();
|
|
158
|
+
|
|
159
|
+
// Both are required if there is a `kiosk_lock_rule`.
|
|
160
|
+
// Optional otherwise. Function throws an error if there's a kiosk_lock_rule and these are missing.
|
|
161
|
+
const extraParams = {
|
|
162
|
+
ownedKiosk,
|
|
163
|
+
ownedKioskCap,
|
|
164
|
+
};
|
|
165
|
+
// Define the environment.
|
|
166
|
+
// To use a custom package address for rules, you could call:
|
|
167
|
+
// const environment = customEnvironment('<PackageAddress>');
|
|
168
|
+
const environment = testnetEnvironment;
|
|
169
|
+
|
|
170
|
+
// Extra params. Optional, but required if the user tries to resolve a `kiosk_lock_rule`.
|
|
171
|
+
// Purchases the item. Supports `kiosk_lock_rule`, `royalty_rule` (accepts combination too).
|
|
172
|
+
const result = purchaseAndResolvePolicies(
|
|
173
|
+
tx,
|
|
174
|
+
item.type,
|
|
175
|
+
item.listing.price,
|
|
176
|
+
kioskId,
|
|
177
|
+
item.objectId,
|
|
178
|
+
policy[0],
|
|
179
|
+
environment,
|
|
180
|
+
extraParams,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
// result = {item: <the_purchased_item>, canTransfer: true/false // depending on whether there was a kiosk lock rule }
|
|
184
|
+
// If the item didn't have a kiosk_lock_rule, you need to do something with it.
|
|
185
|
+
// For example, place it in your own kiosk. (demonstrated below)
|
|
186
|
+
if (result.canTransfer) place(tx, item.type, ownedKiosk, ownedKioskCap, result.item);
|
|
187
|
+
|
|
188
|
+
// ...finally, sign PTB & execute it.
|
|
189
|
+
};
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### After
|
|
193
|
+
|
|
194
|
+
Using the new SDK, you can build the same transaction as follows:
|
|
195
|
+
|
|
196
|
+
> This works with both personal and non-personal kiosks.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
|
|
200
|
+
// You need to do this only once and re-use it in the application.
|
|
201
|
+
const client = new SuiJsonRpcClient({
|
|
202
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
203
|
+
network: 'mainnet',
|
|
204
|
+
}).$extend(kiosk());
|
|
205
|
+
|
|
206
|
+
// An Item as returned from `client.kiosk.getKiosk()` call.
|
|
207
|
+
const item = {
|
|
208
|
+
isLocked: false,
|
|
209
|
+
objectId: '0xb892d61a9992a10c9453efcdbd14ca9720d7dc1000a2048224209c9e544ed223',
|
|
210
|
+
type: '0x52852c4ba80040395b259c641e70b702426a58990ff73cecf5afd31954429090::test::TestItem',
|
|
211
|
+
kioskId: '0xSomeKioskAddress',
|
|
212
|
+
listing: {
|
|
213
|
+
isExclusive: false,
|
|
214
|
+
listingId: '0x368b512ff2514dbea814f26ec9a3d41198c00e8ed778099961e9ed22a9f0032b',
|
|
215
|
+
price: '20000000000', // in MIST
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const purchase = async () => {
|
|
220
|
+
// Assume you have saved the user's preferred kiosk Cap somewhere in your app's state.
|
|
221
|
+
// You wouldn't need to query this for every purchase.
|
|
222
|
+
const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address: '0xSomeAddress' });
|
|
223
|
+
|
|
224
|
+
const tx = new Transaction();
|
|
225
|
+
|
|
226
|
+
const kioskTx = new KioskTransaction({
|
|
227
|
+
transaction: tx,
|
|
228
|
+
kioskClient: client.kiosk,
|
|
229
|
+
cap: kioskOwnerCaps[0],
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Purchase the item and resolve the rules.
|
|
233
|
+
await kioskTx.purchaseAndResolve({
|
|
234
|
+
itemType: item.type,
|
|
235
|
+
itemId: item.objectId,
|
|
236
|
+
price: item.listing.price,
|
|
237
|
+
sellerKiosk: item.kioskId,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
kioskTx.finalize();
|
|
241
|
+
};
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Attach rules to transfer policy
|
|
245
|
+
|
|
246
|
+
The following example was taken from the original Kiosk SDK V1 documentation.
|
|
247
|
+
|
|
248
|
+
### Before
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
|
|
252
|
+
attachKioskLockRule,
|
|
253
|
+
attachRoyaltyRule,
|
|
254
|
+
createTransferPolicy,
|
|
255
|
+
percentageToBasisPoints,
|
|
256
|
+
testnetEnvironment,
|
|
257
|
+
} from '@mysten/kiosk';
|
|
258
|
+
|
|
259
|
+
// Attaches a royalty rule of 1% or 0.1 SUI (whichever is bigger)
|
|
260
|
+
// as well as a kiosk lock, making the objects tradeable only from/to a kiosk.
|
|
261
|
+
const attachStrongRoyalties = async () => {
|
|
262
|
+
const type = 'SomePackageId::type::MyType'; // the Type for which we're attaching rules.
|
|
263
|
+
const policyId = 'policyObjectId'; // the transfer Policy ID that was created for that Type.
|
|
264
|
+
const transferPolicyCap = 'transferPolicyCapId'; // the transferPolicyCap for that policy.
|
|
265
|
+
|
|
266
|
+
// Royalties configuration.
|
|
267
|
+
const percentage = 2.55; // 2.55%
|
|
268
|
+
const minAmount = 100_000_000; // 0.1 SUI.
|
|
269
|
+
|
|
270
|
+
// The environment on which we're referencing the rules package.
|
|
271
|
+
// Use `mainnetEnvironment` for mainnet.
|
|
272
|
+
const environment = testnetEnvironment;
|
|
273
|
+
|
|
274
|
+
const tx = new Transaction();
|
|
275
|
+
|
|
276
|
+
attachKioskLockRule(tx, type, policyId, policyCapId, environment);
|
|
277
|
+
attachRoyaltyRule(
|
|
278
|
+
tx,
|
|
279
|
+
type,
|
|
280
|
+
policyId,
|
|
281
|
+
policyCapId,
|
|
282
|
+
percentageToBasisPoints(percentage),
|
|
283
|
+
minAmount,
|
|
284
|
+
environment,
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
// ... continue to sign and execute the transaction
|
|
288
|
+
// ...
|
|
289
|
+
};
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### After
|
|
293
|
+
|
|
294
|
+
On the new SDK, the same transaction can be built as follows:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
|
|
298
|
+
// You need to do this only once and re-use it in the application.
|
|
299
|
+
const client = new SuiJsonRpcClient({
|
|
300
|
+
url: getJsonRpcFullnodeUrl('mainnet'),
|
|
301
|
+
network: 'mainnet',
|
|
302
|
+
}).$extend(kiosk());
|
|
303
|
+
|
|
304
|
+
const adjustPolicy = async () => {
|
|
305
|
+
const tx = new Transaction();
|
|
306
|
+
|
|
307
|
+
// You could have more than one cap, since you can create more than one transfer policy.
|
|
308
|
+
const policyCaps = await client.kiosk.getOwnedTransferPoliciesByType({
|
|
309
|
+
type: `SomePackageId::type::MyType`,
|
|
310
|
+
address: '0xOwnerAddress',
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
new TransferPolicyTransaction({ transaction: tx, kioskClient: client.kiosk, cap: policyCaps[0] })
|
|
314
|
+
.addRoyaltyRule(percentageToBasisPoints(2.55), 100_000_000)
|
|
315
|
+
.addLockRule();
|
|
316
|
+
|
|
317
|
+
// ... continue to sign and execute the transaction
|
|
318
|
+
// ...
|
|
319
|
+
};
|
|
320
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Kiosk SDK
|
|
2
|
+
|
|
3
|
+
> TypeScript SDK for interacting with Sui Kiosk on-chain commerce
|
|
4
|
+
|
|
5
|
+
Kiosk SDK is a tool to interact with Sui/Mysten Kiosk. You can use it to query kiosk related data,
|
|
6
|
+
build transactions to interact, and extend Kiosk to support custom rules.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh npm2yarn
|
|
11
|
+
npm i @mysten/kiosk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## About
|
|
15
|
+
|
|
16
|
+
The Kiosk SDK exports a client extension that integrates with Sui clients. Add it to your client
|
|
17
|
+
using `$extend(kiosk())` to access kiosk functionality via `client.kiosk`.
|
|
18
|
+
|
|
19
|
+
> **Note:** The Kiosk SDK requires `SuiJsonRpcClient` or `SuiGraphQLClient`. It does not work with
|
|
20
|
+
> `SuiGrpcClient` because it uses event queries that are not available in gRPC.
|
|
21
|
+
|
|
22
|
+
- [Read more about setting up the Kiosk client extension](/kiosk/kiosk-client/introduction)
|