@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,172 @@
|
|
|
1
|
+
# React
|
|
2
|
+
|
|
3
|
+
> Set up dApp Kit in a React application
|
|
4
|
+
|
|
5
|
+
This guide walks you through integrating dApp Kit into a React application.
|
|
6
|
+
|
|
7
|
+
## Quick Start with create-dapp
|
|
8
|
+
|
|
9
|
+
The fastest way to get started is using our CLI tool:
|
|
10
|
+
|
|
11
|
+
```sh npm2yarn
|
|
12
|
+
npm create @mysten/dapp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This creates a new project with:
|
|
16
|
+
|
|
17
|
+
- React + TypeScript + Vite
|
|
18
|
+
- Tailwind CSS v4 for styling
|
|
19
|
+
- dApp Kit pre-configured
|
|
20
|
+
- Example wallet connection UI
|
|
21
|
+
|
|
22
|
+
Choose from two templates:
|
|
23
|
+
|
|
24
|
+
- **react-client-dapp**: Basic wallet connection and object display
|
|
25
|
+
- **react-e2e-counter**: Full example with Move smart contract and codegen
|
|
26
|
+
|
|
27
|
+
See the [create-dapp guide](/dapp-kit/getting-started/create-dapp) for more details.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Manual Installation
|
|
32
|
+
|
|
33
|
+
```sh npm2yarn
|
|
34
|
+
npm i @mysten/dapp-kit-react @mysten/sui
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Setup
|
|
38
|
+
|
|
39
|
+
### 1. Create a dApp Kit Instance
|
|
40
|
+
|
|
41
|
+
Create a file to configure your dApp Kit instance:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// dapp-kit.ts
|
|
45
|
+
|
|
46
|
+
const GRPC_URLS = {
|
|
47
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
networks: ['testnet'],
|
|
51
|
+
createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Register types for hook type inference
|
|
55
|
+
declare module '@mysten/dapp-kit-react' {
|
|
56
|
+
interface Register {
|
|
57
|
+
dAppKit: typeof dAppKit;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 2. Add the Provider
|
|
63
|
+
|
|
64
|
+
Wrap your application with `DAppKitProvider`:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
// App.tsx
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<DAppKitProvider dAppKit={dAppKit}>
|
|
71
|
+
<div>
|
|
72
|
+
<h1>My Sui dApp</h1>
|
|
73
|
+
<ConnectButton />
|
|
74
|
+
<WalletStatus />
|
|
75
|
+
</div>
|
|
76
|
+
</DAppKitProvider>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. Display Connection Status
|
|
82
|
+
|
|
83
|
+
Use hooks to access wallet state:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
|
|
87
|
+
function WalletStatus() {
|
|
88
|
+
const account = useCurrentAccount();
|
|
89
|
+
const wallet = useCurrentWallet();
|
|
90
|
+
const network = useCurrentNetwork();
|
|
91
|
+
|
|
92
|
+
if (!account) {
|
|
93
|
+
return <p>Connect your wallet to get started</p>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div>
|
|
98
|
+
<p>Wallet: {wallet?.name}</p>
|
|
99
|
+
<p>Address: {account.address}</p>
|
|
100
|
+
<p>Network: {network}</p>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 4. Execute Transactions
|
|
107
|
+
|
|
108
|
+
Use the `useDAppKit` hook to sign and execute transactions:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
|
|
112
|
+
function TransferButton() {
|
|
113
|
+
const dAppKit = useDAppKit();
|
|
114
|
+
const account = useCurrentAccount();
|
|
115
|
+
|
|
116
|
+
async function handleTransfer() {
|
|
117
|
+
const tx = new Transaction();
|
|
118
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], 'RECIPIENT_ADDRESS');
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
122
|
+
|
|
123
|
+
if (result.FailedTransaction) {
|
|
124
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error('Transaction failed:', error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<button onClick={handleTransfer} disabled={!account}>
|
|
135
|
+
Send Transaction
|
|
136
|
+
</button>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Available Hooks
|
|
142
|
+
|
|
143
|
+
| Hook | Description |
|
|
144
|
+
| ------------------------------------------------------------------ | ---------------------------------------- |
|
|
145
|
+
| [useDAppKit](/dapp-kit/react/hooks/use-dapp-kit) | Access the dApp Kit instance and actions |
|
|
146
|
+
| [useWalletConnection](/dapp-kit/react/hooks/use-wallet-connection) | Full connection state with status flags |
|
|
147
|
+
| [useCurrentAccount](/dapp-kit/react/hooks/use-current-account) | Currently selected account |
|
|
148
|
+
| [useCurrentWallet](/dapp-kit/react/hooks/use-current-wallet) | Currently connected wallet |
|
|
149
|
+
| [useCurrentNetwork](/dapp-kit/react/hooks/use-current-network) | Current network |
|
|
150
|
+
| [useCurrentClient](/dapp-kit/react/hooks/use-current-client) | SuiClient for current network |
|
|
151
|
+
| [useWallets](/dapp-kit/react/hooks/use-wallets) | List of available wallets |
|
|
152
|
+
|
|
153
|
+
## Components
|
|
154
|
+
|
|
155
|
+
| Component | Description |
|
|
156
|
+
| ---------------------------------------------------------- | --------------------------------- |
|
|
157
|
+
| [ConnectButton](/dapp-kit/react/components/connect-button) | Complete wallet connection UI |
|
|
158
|
+
| [ConnectModal](/dapp-kit/react/components/connect-modal) | Standalone wallet selection modal |
|
|
159
|
+
| [DAppKitProvider](/dapp-kit/react/dapp-kit-provider) | Context provider for hooks |
|
|
160
|
+
|
|
161
|
+
## Example Application
|
|
162
|
+
|
|
163
|
+
See the complete
|
|
164
|
+
[React example](https://github.com/MystenLabs/ts-sdks/tree/main/packages/dapp-kit-next/examples/react/simple)
|
|
165
|
+
on GitHub.
|
|
166
|
+
|
|
167
|
+
## Next Steps
|
|
168
|
+
|
|
169
|
+
- [DAppKitProvider](/dapp-kit/react/dapp-kit-provider) - Provider configuration
|
|
170
|
+
- [Hooks Reference](/dapp-kit/react/hooks) - All available hooks
|
|
171
|
+
- [Components](/dapp-kit/react/components) - UI components
|
|
172
|
+
- [Theming](/dapp-kit/theming) - Customize appearance
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Vue
|
|
2
|
+
|
|
3
|
+
> Set up dApp Kit in a Vue application
|
|
4
|
+
|
|
5
|
+
This guide walks you through integrating dApp Kit into a Vue application using Web Components and
|
|
6
|
+
direct store access.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh npm2yarn
|
|
11
|
+
npm i @mysten/dapp-kit-core @mysten/sui @nanostores/vue
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
### 1. Create a dApp Kit Instance
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// src/dapp-kit.ts
|
|
20
|
+
|
|
21
|
+
const GRPC_URLS = {
|
|
22
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
networks: ['testnet'],
|
|
26
|
+
createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Register Web Components
|
|
31
|
+
|
|
32
|
+
Import the web components in your app entry point:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// src/main.ts
|
|
36
|
+
|
|
37
|
+
createApp(App).mount('#app');
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. Use the Connect Button
|
|
41
|
+
|
|
42
|
+
```vue
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div>
|
|
49
|
+
<h1>My Sui dApp</h1>
|
|
50
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 4. Access Connection State
|
|
56
|
+
|
|
57
|
+
Use `@nanostores/vue` for reactive state:
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<script setup lang="ts">
|
|
61
|
+
|
|
62
|
+
const connection = useStore(dAppKit.stores.$connection);
|
|
63
|
+
const network = useStore(dAppKit.stores.$currentNetwork);
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div>
|
|
68
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
69
|
+
|
|
70
|
+
<div v-if="connection.account">
|
|
71
|
+
<p>Wallet: {{ connection.wallet?.name }}</p>
|
|
72
|
+
<p>Address: {{ connection.account.address }}</p>
|
|
73
|
+
<p>Network: {{ network }}</p>
|
|
74
|
+
</div>
|
|
75
|
+
<p v-else>Connect your wallet to get started</p>
|
|
76
|
+
</div>
|
|
77
|
+
</template>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 5. Execute Transactions
|
|
81
|
+
|
|
82
|
+
```vue
|
|
83
|
+
<script setup lang="ts">
|
|
84
|
+
|
|
85
|
+
const connection = useStore(dAppKit.stores.$connection);
|
|
86
|
+
|
|
87
|
+
async function handleTransfer() {
|
|
88
|
+
const tx = new Transaction();
|
|
89
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], connection.value.account!.address);
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
93
|
+
|
|
94
|
+
if (result.FailedTransaction) {
|
|
95
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
alert(`Transaction: ${result.Transaction.digest}`);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error('Transaction failed:', error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<template>
|
|
106
|
+
<div>
|
|
107
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
108
|
+
|
|
109
|
+
<button v-if="connection.account" @click="handleTransfer">Send Transaction</button>
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Complete Example
|
|
115
|
+
|
|
116
|
+
```vue
|
|
117
|
+
<script setup lang="ts">
|
|
118
|
+
|
|
119
|
+
const connection = useStore(dAppKit.stores.$connection);
|
|
120
|
+
const network = useStore(dAppKit.stores.$currentNetwork);
|
|
121
|
+
|
|
122
|
+
async function handleTransfer() {
|
|
123
|
+
if (!connection.value.account) return;
|
|
124
|
+
|
|
125
|
+
const tx = new Transaction();
|
|
126
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], connection.value.account.address);
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
130
|
+
|
|
131
|
+
if (result.FailedTransaction) {
|
|
132
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
alert(`Transaction successful: ${result.Transaction.digest}`);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error('Transaction failed:', error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<template>
|
|
143
|
+
<div class="app">
|
|
144
|
+
<h1>My Sui dApp</h1>
|
|
145
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
146
|
+
|
|
147
|
+
<div v-if="connection.account" class="wallet-info">
|
|
148
|
+
<p>Wallet: {{ connection.wallet?.name }}</p>
|
|
149
|
+
<p>Address: {{ connection.account.address }}</p>
|
|
150
|
+
<p>Network: {{ network }}</p>
|
|
151
|
+
<button @click="handleTransfer">Send Test Transaction</button>
|
|
152
|
+
</div>
|
|
153
|
+
<p v-else>Connect your wallet to get started</p>
|
|
154
|
+
</div>
|
|
155
|
+
</template>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Web Components
|
|
159
|
+
|
|
160
|
+
Vue works with dApp Kit's Web Components through property binding:
|
|
161
|
+
|
|
162
|
+
| Component | Usage |
|
|
163
|
+
| -------------- | ---------------------------------------------------------------------- |
|
|
164
|
+
| Connect Button | `<mysten-dapp-kit-connect-button :instance="dAppKit" />` |
|
|
165
|
+
| Connect Modal | `<mysten-dapp-kit-connect-modal :instance="dAppKit" :open="isOpen" />` |
|
|
166
|
+
|
|
167
|
+
See [Web Components](/dapp-kit/web-components/connect-button) for full documentation.
|
|
168
|
+
|
|
169
|
+
## Available Stores
|
|
170
|
+
|
|
171
|
+
Access these stores via `dAppKit.stores`:
|
|
172
|
+
|
|
173
|
+
| Store | Description |
|
|
174
|
+
| ----------------- | ------------------------------------------------- |
|
|
175
|
+
| `$connection` | Connection state with wallet, account, and status |
|
|
176
|
+
| `$currentNetwork` | Current network string |
|
|
177
|
+
| `$currentClient` | SuiClient for current network |
|
|
178
|
+
| `$wallets` | List of available wallets |
|
|
179
|
+
|
|
180
|
+
See [State Management](/dapp-kit/state) for full documentation.
|
|
181
|
+
|
|
182
|
+
## Example Application
|
|
183
|
+
|
|
184
|
+
See the complete
|
|
185
|
+
[Vue example](https://github.com/MystenLabs/ts-sdks/tree/main/packages/dapp-kit-next/examples/vue/simple)
|
|
186
|
+
on GitHub.
|
|
187
|
+
|
|
188
|
+
## Next Steps
|
|
189
|
+
|
|
190
|
+
- [Web Components](/dapp-kit/web-components/connect-button) - Component documentation
|
|
191
|
+
- [State Management](/dapp-kit/state) - Store details
|
|
192
|
+
- [Actions](/dapp-kit/actions/connect-wallet) - All available actions
|
|
193
|
+
- [Theming](/dapp-kit/theming) - Customize appearance
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Sui dApp Kit
|
|
2
|
+
|
|
3
|
+
> Build Sui dApps with framework-agnostic core and React bindings
|
|
4
|
+
|
|
5
|
+
> **Note:** **Migrating from @mysten/dapp-kit?** If you're currently using the legacy `@mysten/dapp-kit`
|
|
6
|
+
> package, check out our [Migration Guide](/sui/migrations/sui-2.0/dapp-kit) to upgrade to the new
|
|
7
|
+
> packages with gRPC and GraphQL support.
|
|
8
|
+
|
|
9
|
+
The Sui dApp Kit provides tools and components for building decentralized applications on the Sui
|
|
10
|
+
network. The SDK consists of two packages that work together:
|
|
11
|
+
|
|
12
|
+
## Packages
|
|
13
|
+
|
|
14
|
+
### @mysten/dapp-kit-core
|
|
15
|
+
|
|
16
|
+
Framework-agnostic core that works with vanilla JS, React, Vue, or any framework:
|
|
17
|
+
|
|
18
|
+
- Action-based API for direct wallet operations
|
|
19
|
+
- Web Components for universal UI elements
|
|
20
|
+
- Automatic state management with nanostores
|
|
21
|
+
- Smaller bundle size and improved performance
|
|
22
|
+
|
|
23
|
+
### @mysten/dapp-kit-react
|
|
24
|
+
|
|
25
|
+
React bindings for the core package:
|
|
26
|
+
|
|
27
|
+
- React hooks for state and actions
|
|
28
|
+
- React component wrappers for Web Components
|
|
29
|
+
- Seamless integration with React applications
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
Choose the installation method based on your framework:
|
|
34
|
+
|
|
35
|
+
### For React Applications
|
|
36
|
+
|
|
37
|
+
```sh npm2yarn
|
|
38
|
+
npm i @mysten/dapp-kit-react @mysten/sui
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Vanilla JavaScript and other frameworks
|
|
42
|
+
|
|
43
|
+
```sh npm2yarn
|
|
44
|
+
npm i @mysten/dapp-kit-core @mysten/sui
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Getting Started
|
|
48
|
+
|
|
49
|
+
Check the framework-specific guides:
|
|
50
|
+
|
|
51
|
+
- [React](/dapp-kit/getting-started/react)
|
|
52
|
+
- [Next.js](/dapp-kit/getting-started/next-js)
|
|
53
|
+
- [Vue](/dapp-kit/getting-started/vue)
|
|
54
|
+
|
|
55
|
+
## Legacy Package
|
|
56
|
+
|
|
57
|
+
### @mysten/dapp-kit (Legacy)
|
|
58
|
+
|
|
59
|
+
See the [Legacy dApp Kit documentation](/dapp-kit/legacy).
|
|
60
|
+
|
|
61
|
+
The original React-focused version of the dApp Kit. This package provides:
|
|
62
|
+
|
|
63
|
+
- React hooks for wallet connection and blockchain queries
|
|
64
|
+
- Pre-built UI components with Radix UI
|
|
65
|
+
- Integration with TanStack React Query
|
|
66
|
+
- Comprehensive wallet state management
|
|
67
|
+
|
|
68
|
+
> **Warning:** **Deprecated JSON RPC Only**: This legacy package only works with the deprecated JSON RPC API and
|
|
69
|
+
> will not be updated to support gRPC or GraphQL. All new projects should use
|
|
70
|
+
> `@mysten/dapp-kit-core` and `@mysten/dapp-kit-react`.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# dApp Kit
|
|
2
|
+
> Build Sui dApps with @mysten/dapp-kit-core and @mysten/dapp-kit-react
|
|
3
|
+
|
|
4
|
+
- [Sui dApp Kit](./index.md): Build Sui dApps with framework-agnostic core and React bindings
|
|
5
|
+
- [@mysten/create-dapp](./getting-started/create-dapp.md): Create a Sui dApp with one command
|
|
6
|
+
- [React](./getting-started/react.md): Set up dApp Kit in a React application
|
|
7
|
+
- [Next.js](./getting-started/next-js.md): Set up dApp Kit in a Next.js application
|
|
8
|
+
- [Vue](./getting-started/vue.md): Set up dApp Kit in a Vue application
|
|
9
|
+
- [DApp Kit Instance](./dapp-kit-instance.md): Create and configure a DAppKit instance for wallet and client management
|
|
10
|
+
- [State](./state.md): Access and subscribe to wallet connection state in dApp Kit
|
|
11
|
+
- [Connect Wallet](./actions/connect-wallet.md): Programmatically connect to a Sui wallet
|
|
12
|
+
- [Disconnect Wallet](./actions/disconnect-wallet.md): Programmatically disconnect from a Sui wallet
|
|
13
|
+
- [Sign and Execute Transaction](./actions/sign-and-execute-transaction.md): Sign and execute a transaction using the connected wallet
|
|
14
|
+
- [Sign Personal Message](./actions/sign-personal-message.md): Sign an arbitrary message with the connected wallet
|
|
15
|
+
- [Sign Transaction](./actions/sign-transaction.md): Sign a transaction without executing it
|
|
16
|
+
- [Switch Account](./actions/switch-account.md): Switch the active account in the connected wallet
|
|
17
|
+
- [Switch Network](./actions/switch-network.md): Switch the active network for the dApp Kit instance
|
|
18
|
+
- [DAppKitProvider](./react/dapp-kit-provider.md): React context provider for dApp Kit configuration
|
|
19
|
+
- [React Hooks](./react/hooks/index.md): React hooks for accessing dApp Kit state and actions
|
|
20
|
+
- [useDAppKit](./react/hooks/use-dapp-kit.md): React hook to access the full dApp Kit instance
|
|
21
|
+
- [React Components](./react/components/index.md): Pre-built React UI components for wallet interaction
|
|
22
|
+
- [Connect Button](./react/components/connect-button.md): React button component for wallet connection
|
|
23
|
+
- [Connect Modal](./react/components/connect-modal.md): React modal component for wallet selection
|
|
24
|
+
- [Connect Button](./web-components/connect-button.md): Framework-agnostic web component for wallet connection
|
|
25
|
+
- [Connect Modal](./web-components/connect-modal.md): Framework-agnostic web component for wallet selection
|
|
26
|
+
- [Theming](./theming.md): Customize the appearance of dApp Kit UI components
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Connect Button
|
|
2
|
+
|
|
3
|
+
> React button component for wallet connection
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
<ConnectButton
|
|
9
|
+
modalOptions={{
|
|
10
|
+
filterFn: (wallet) => wallet.name !== 'Excluded Wallet',
|
|
11
|
+
sortFn: (a, b) => a.name.localeCompare(b.name),
|
|
12
|
+
}}
|
|
13
|
+
/>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
> Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
|
|
17
|
+
> page reload. This provides a seamless user experience but can be
|
|
18
|
+
> [disabled](/dapp-kit/dapp-kit-instance#disabling-auto-connect) if needed.
|
|
19
|
+
|
|
20
|
+
## Props
|
|
21
|
+
|
|
22
|
+
- **instance** (optional) - dApp Kit instance. If not provided, uses the instance from context.
|
|
23
|
+
- **modalOptions** (optional) - Configuration options for the connect modal
|
|
24
|
+
- **filterFn** (optional) - Function to filter available wallets
|
|
25
|
+
- Type: `(wallet: UiWallet, index: number, array: UiWallet[]) => boolean`
|
|
26
|
+
- **sortFn** (optional) - Function to sort available wallets
|
|
27
|
+
- Type: `(a: UiWallet, b: UiWallet) => number`
|
|
28
|
+
|
|
29
|
+
## Custom Button Text
|
|
30
|
+
|
|
31
|
+
Use the slot to customize the button content when disconnected:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
<ConnectButton>
|
|
35
|
+
<span>🔗 Link Wallet</span>
|
|
36
|
+
</ConnectButton>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Server-Side Rendering (SSR)
|
|
40
|
+
|
|
41
|
+
The `<ConnectButton />` component can be only client-side rendered, as wallets are detected in the
|
|
42
|
+
browser. For Next.js guide see [here](/dapp-kit/getting-started/next-js).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Connect Modal
|
|
2
|
+
|
|
3
|
+
> React modal component for wallet selection
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
|
|
9
|
+
const [open, setOpen] = useState(false);
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<button onClick={() => setOpen(true)}>Connect Wallet</button>
|
|
13
|
+
<ConnectModal open={open} />
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Props
|
|
20
|
+
|
|
21
|
+
- **open** (optional) - Boolean to control modal visibility. If not provided, the modal can be
|
|
22
|
+
controlled by calling `show()` and `close()` methods directly on the component ref.
|
|
23
|
+
- **instance** (optional) - dApp Kit instance. If not provided, uses the instance from context
|
|
24
|
+
- **filterFn** (optional) - Function to filter available wallets
|
|
25
|
+
- Type: `(wallet: UiWallet, index: number, array: UiWallet[]) => boolean`
|
|
26
|
+
- **sortFn** (optional) - Function to sort available wallets
|
|
27
|
+
- Type: `(a: UiWallet, b: UiWallet) => number`
|
|
28
|
+
|
|
29
|
+
### Example
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
<ConnectModal
|
|
33
|
+
open={open}
|
|
34
|
+
filterFn={(wallet) => wallet.name !== 'ExcludedWallet'}
|
|
35
|
+
sortFn={(a, b) => a.name.localeCompare(b.name)}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Modal States
|
|
40
|
+
|
|
41
|
+
The modal displays different views based on connection status:
|
|
42
|
+
|
|
43
|
+
- **Wallet Selection**: Shows available wallets to choose from
|
|
44
|
+
- **Connecting**: Displays loading state while connecting to selected wallet
|
|
45
|
+
- **Error**: Shows error message with retry option when connection fails
|
|
46
|
+
- **Request Cancelled**: Appears when user cancels the wallet connection request
|
|
47
|
+
|
|
48
|
+
## Server-Side Rendering (SSR)
|
|
49
|
+
|
|
50
|
+
The `<ConnectModal />` component can be only client-side rendered, as wallets are detected in the
|
|
51
|
+
browser. For Next.js guide see [here](/dapp-kit/getting-started/next-js).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# React Components
|
|
2
|
+
|
|
3
|
+
> Pre-built React UI components for wallet interaction
|
|
4
|
+
|
|
5
|
+
The `@mysten/dapp-kit-react` package provides pre-built React components for common wallet
|
|
6
|
+
interactions.
|
|
7
|
+
|
|
8
|
+
## Available Components
|
|
9
|
+
|
|
10
|
+
- [`ConnectButton`](/dapp-kit/react/components/connect-button) - A button that opens the wallet
|
|
11
|
+
connection modal and displays account info when connected
|
|
12
|
+
- [`ConnectModal`](/dapp-kit/react/components/connect-modal) - A modal dialog for selecting and
|
|
13
|
+
connecting to a wallet
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# DAppKitProvider
|
|
2
|
+
|
|
3
|
+
> React context provider for dApp Kit configuration
|
|
4
|
+
|
|
5
|
+
The `DAppKitProvider` is a React context provider that makes your dApp Kit instance available
|
|
6
|
+
throughout your React application. It must wrap any components that use dApp Kit hooks.
|
|
7
|
+
|
|
8
|
+
## Basic Usage
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<DAppKitProvider dAppKit={dAppKit}>
|
|
14
|
+
<YourApp />
|
|
15
|
+
</DAppKitProvider>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Props
|
|
21
|
+
|
|
22
|
+
- **dAppKit**: The dApp Kit instance created with `createDAppKit`
|
|
23
|
+
|
|
24
|
+
## Provider Setup Patterns
|
|
25
|
+
|
|
26
|
+
### With Custom Configuration
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
|
|
30
|
+
const GRPC_URLS = {
|
|
31
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
const dAppKit = createDAppKit({
|
|
35
|
+
networks: ['testnet'],
|
|
36
|
+
createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
|
|
37
|
+
autoConnect: true,
|
|
38
|
+
storage: localStorage,
|
|
39
|
+
storageKey: 'myapp_dappkit',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// global type registration necessary for the hooks to work correctly
|
|
43
|
+
declare module '@mysten/dapp-kit-react' {
|
|
44
|
+
interface Register {
|
|
45
|
+
dAppKit: typeof dAppKit;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<DAppKitProvider dAppKit={dAppKit}>
|
|
51
|
+
<YourApp />
|
|
52
|
+
</DAppKitProvider>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Using Hooks Inside the Provider
|
|
58
|
+
|
|
59
|
+
Once your app is wrapped with `DAppKitProvider`, you can use any dApp Kit hooks in child components:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
|
|
63
|
+
const dAppKit = useDAppKit();
|
|
64
|
+
const account = useCurrentAccount();
|
|
65
|
+
const network = useCurrentNetwork();
|
|
66
|
+
const handleConnect = async () => {
|
|
67
|
+
await dAppKit.connectWallet({ wallet });
|
|
68
|
+
};
|
|
69
|
+
return (
|
|
70
|
+
<div>
|
|
71
|
+
<p>Network: {network}</p>
|
|
72
|
+
<p>Account: {account?.address}</p>
|
|
73
|
+
<button onClick={handleConnect}>Connect</button>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> All dApp Kit hooks must be used within components that are descendants of `DAppKitProvider`. Using
|
|
80
|
+
> them outside will result in an error.
|
|
81
|
+
|
|
82
|
+
## Server-Side Rendering (SSR)
|
|
83
|
+
|
|
84
|
+
While `DAppKitProvider` itself is SSR-safe, components that interact with wallets should be
|
|
85
|
+
client-side rendered, as wallets are detected in the browser. For Next.js guide see
|
|
86
|
+
[here](/dapp-kit/getting-started/next-js).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# React Hooks
|
|
2
|
+
|
|
3
|
+
> React hooks for accessing dApp Kit state and actions
|
|
4
|
+
|
|
5
|
+
The `@mysten/dapp-kit-react` package provides a set of hooks for interacting with wallets and the
|
|
6
|
+
Sui blockchain in React applications.
|
|
7
|
+
|
|
8
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
9
|
+
> [DAppKitProvider](/dapp-kit/react/dapp-kit-provider). Using them outside will result in an error.
|
|
10
|
+
|
|
11
|
+
## Available Hooks
|
|
12
|
+
|
|
13
|
+
- [`useDAppKit`](/dapp-kit/react/hooks/use-dapp-kit) - Access the dApp Kit instance for calling
|
|
14
|
+
actions directly
|
|
15
|
+
- [`useCurrentAccount`](/dapp-kit/react/hooks/use-current-account) - Get the currently selected
|
|
16
|
+
account
|
|
17
|
+
- [`useCurrentClient`](/dapp-kit/react/hooks/use-current-client) - Get the blockchain client for the
|
|
18
|
+
current network
|
|
19
|
+
- [`useCurrentNetwork`](/dapp-kit/react/hooks/use-current-network) - Get the currently selected
|
|
20
|
+
network
|
|
21
|
+
- [`useCurrentWallet`](/dapp-kit/react/hooks/use-current-wallet) - Get the currently connected
|
|
22
|
+
wallet
|
|
23
|
+
- [`useWalletConnection`](/dapp-kit/react/hooks/use-wallet-connection) - Get wallet connection
|
|
24
|
+
status and actions
|
|
25
|
+
- [`useWallets`](/dapp-kit/react/hooks/use-wallets) - Get all available wallets
|