@mysten/dapp-kit-core 1.1.4 → 1.2.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/CHANGELOG.md +26 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{types-DCpd4A8C.d.mts → types-CujIIq_S.d.mts} +2 -2
- package/dist/types-CujIIq_S.d.mts.map +1 -0
- package/dist/web/index.d.mts +1 -1
- package/docs/actions/connect-wallet.md +68 -0
- package/docs/actions/disconnect-wallet.md +37 -0
- package/docs/actions/sign-and-execute-transaction.md +95 -0
- package/docs/actions/sign-personal-message.md +57 -0
- package/docs/actions/sign-transaction.md +64 -0
- package/docs/actions/switch-account.md +36 -0
- package/docs/actions/switch-network.md +36 -0
- package/docs/dapp-kit-instance.md +163 -0
- package/docs/getting-started/create-dapp.md +151 -0
- package/docs/getting-started/next-js.md +162 -0
- package/docs/getting-started/react.md +170 -0
- package/docs/getting-started/vue.md +188 -0
- package/docs/index.md +70 -0
- package/docs/llms-index.md +34 -0
- package/docs/react/components/connect-button.md +42 -0
- package/docs/react/components/connect-modal.md +51 -0
- package/docs/react/components/index.md +13 -0
- package/docs/react/dapp-kit-provider.md +86 -0
- package/docs/react/hooks/index.md +25 -0
- package/docs/react/hooks/use-current-account.md +33 -0
- package/docs/react/hooks/use-current-client.md +36 -0
- package/docs/react/hooks/use-current-network.md +28 -0
- package/docs/react/hooks/use-current-wallet.md +36 -0
- package/docs/react/hooks/use-dapp-kit.md +100 -0
- package/docs/react/hooks/use-wallet-connection.md +48 -0
- package/docs/react/hooks/use-wallets.md +33 -0
- package/docs/state.md +168 -0
- package/docs/theming.md +196 -0
- package/docs/web-components/connect-button.md +87 -0
- package/docs/web-components/connect-modal.md +176 -0
- package/package.json +6 -4
- package/src/core/initializers/registered-wallets.ts +13 -1
- package/src/index.ts +1 -0
- package/src/wallets/index.ts +2 -2
- package/dist/types-DCpd4A8C.d.mts.map +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Next.js
|
|
2
|
+
|
|
3
|
+
> Set up dApp Kit in a Next.js application
|
|
4
|
+
|
|
5
|
+
This guide covers integrating dApp Kit into Next.js applications, including handling server-side
|
|
6
|
+
rendering (SSR).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh npm2yarn
|
|
11
|
+
npm i @mysten/dapp-kit-react @mysten/sui
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
### 1. Create a dApp Kit Instance
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// app/dapp-kit.ts
|
|
20
|
+
|
|
21
|
+
const GRPC_URLS = {
|
|
22
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
networks: ['testnet'],
|
|
26
|
+
createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Register types for hook type inference
|
|
30
|
+
declare module '@mysten/dapp-kit-react' {
|
|
31
|
+
interface Register {
|
|
32
|
+
dAppKit: typeof dAppKit;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Create a Client-Only Wrapper
|
|
38
|
+
|
|
39
|
+
Wallet detection only works in the browser, so dApp Kit components must be client-side rendered:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
// app/DAppKitClientProvider.tsx
|
|
43
|
+
'use client';
|
|
44
|
+
|
|
45
|
+
return <DAppKitProvider dAppKit={dAppKit}>{children}</DAppKitProvider>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 3. Use Dynamic Import in Pages
|
|
51
|
+
|
|
52
|
+
Use Next.js dynamic imports with `ssr: false` to prevent server-side rendering:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
// app/page.tsx
|
|
56
|
+
|
|
57
|
+
const DAppKitClientProvider = dynamic(
|
|
58
|
+
() => import('./DAppKitClientProvider').then((mod) => mod.DAppKitClientProvider),
|
|
59
|
+
{ ssr: false },
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const ConnectButton = dynamic(
|
|
63
|
+
() => import('./DAppKitClientProvider').then((mod) => mod.ConnectButton),
|
|
64
|
+
{ ssr: false, loading: () => <button disabled>Loading...</button> },
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<DAppKitClientProvider>
|
|
69
|
+
<main>
|
|
70
|
+
<h1>My Sui dApp</h1>
|
|
71
|
+
<ConnectButton />
|
|
72
|
+
</main>
|
|
73
|
+
</DAppKitClientProvider>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Alternative: Single Client Component
|
|
79
|
+
|
|
80
|
+
For simpler apps, create a single client component:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
// app/WalletApp.tsx
|
|
84
|
+
'use client';
|
|
85
|
+
|
|
86
|
+
function WalletStatus() {
|
|
87
|
+
const account = useCurrentAccount();
|
|
88
|
+
const dAppKit = useDAppKit();
|
|
89
|
+
|
|
90
|
+
if (!account) {
|
|
91
|
+
return <p>Connect your wallet to get started</p>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function handleTransfer() {
|
|
95
|
+
const tx = new Transaction();
|
|
96
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], account.address);
|
|
97
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
98
|
+
|
|
99
|
+
if (result.FailedTransaction) {
|
|
100
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
alert(`Transaction: ${result.Transaction.digest}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div>
|
|
108
|
+
<p>Connected: {account.address}</p>
|
|
109
|
+
<button onClick={handleTransfer}>Send Transaction</button>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<DAppKitProvider dAppKit={dAppKit}>
|
|
116
|
+
<ConnectButton />
|
|
117
|
+
<WalletStatus />
|
|
118
|
+
</DAppKitProvider>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
// app/page.tsx
|
|
125
|
+
|
|
126
|
+
const WalletApp = dynamic(() => import('./WalletApp'), {
|
|
127
|
+
ssr: false,
|
|
128
|
+
loading: () => <p>Loading wallet...</p>,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<main>
|
|
133
|
+
<h1>My Sui dApp</h1>
|
|
134
|
+
<WalletApp />
|
|
135
|
+
</main>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Key Considerations
|
|
141
|
+
|
|
142
|
+
### Why SSR: false?
|
|
143
|
+
|
|
144
|
+
Wallets are detected via the browser's `window` object and the Wallet Standard API. This detection
|
|
145
|
+
cannot happen on the server, so components that interact with wallets must be client-side only.
|
|
146
|
+
|
|
147
|
+
### Hydration Errors
|
|
148
|
+
|
|
149
|
+
If you see hydration errors, ensure all dApp Kit components are wrapped with `ssr: false` dynamic
|
|
150
|
+
imports or are inside a `'use client'` component that's dynamically imported.
|
|
151
|
+
|
|
152
|
+
## Example Application
|
|
153
|
+
|
|
154
|
+
See the complete
|
|
155
|
+
[Next.js example](https://github.com/MystenLabs/ts-sdks/tree/main/packages/dapp-kit-next/examples/next-js/simple)
|
|
156
|
+
on GitHub.
|
|
157
|
+
|
|
158
|
+
## Next Steps
|
|
159
|
+
|
|
160
|
+
- [React Hooks](/dapp-kit/react/hooks) - All available hooks
|
|
161
|
+
- [React Components](/dapp-kit/react/components) - UI components
|
|
162
|
+
- [Theming](/dapp-kit/theming) - Customize appearance
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
function WalletStatus() {
|
|
87
|
+
const account = useCurrentAccount();
|
|
88
|
+
const wallet = useCurrentWallet();
|
|
89
|
+
const network = useCurrentNetwork();
|
|
90
|
+
|
|
91
|
+
if (!account) {
|
|
92
|
+
return <p>Connect your wallet to get started</p>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div>
|
|
97
|
+
<p>Wallet: {wallet?.name}</p>
|
|
98
|
+
<p>Address: {account.address}</p>
|
|
99
|
+
<p>Network: {network}</p>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 4. Execute Transactions
|
|
106
|
+
|
|
107
|
+
Use the `useDAppKit` hook to sign and execute transactions:
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
function TransferButton() {
|
|
111
|
+
const dAppKit = useDAppKit();
|
|
112
|
+
const account = useCurrentAccount();
|
|
113
|
+
|
|
114
|
+
async function handleTransfer() {
|
|
115
|
+
const tx = new Transaction();
|
|
116
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], 'RECIPIENT_ADDRESS');
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
120
|
+
|
|
121
|
+
if (result.FailedTransaction) {
|
|
122
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error('Transaction failed:', error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<button onClick={handleTransfer} disabled={!account}>
|
|
133
|
+
Send Transaction
|
|
134
|
+
</button>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Available Hooks
|
|
140
|
+
|
|
141
|
+
| Hook | Description |
|
|
142
|
+
| ------------------------------------------------------------------ | ---------------------------------------- |
|
|
143
|
+
| [useDAppKit](/dapp-kit/react/hooks/use-dapp-kit) | Access the dApp Kit instance and actions |
|
|
144
|
+
| [useWalletConnection](/dapp-kit/react/hooks/use-wallet-connection) | Full connection state with status flags |
|
|
145
|
+
| [useCurrentAccount](/dapp-kit/react/hooks/use-current-account) | Currently selected account |
|
|
146
|
+
| [useCurrentWallet](/dapp-kit/react/hooks/use-current-wallet) | Currently connected wallet |
|
|
147
|
+
| [useCurrentNetwork](/dapp-kit/react/hooks/use-current-network) | Current network |
|
|
148
|
+
| [useCurrentClient](/dapp-kit/react/hooks/use-current-client) | SuiClient for current network |
|
|
149
|
+
| [useWallets](/dapp-kit/react/hooks/use-wallets) | List of available wallets |
|
|
150
|
+
|
|
151
|
+
## Components
|
|
152
|
+
|
|
153
|
+
| Component | Description |
|
|
154
|
+
| ---------------------------------------------------------- | --------------------------------- |
|
|
155
|
+
| [ConnectButton](/dapp-kit/react/components/connect-button) | Complete wallet connection UI |
|
|
156
|
+
| [ConnectModal](/dapp-kit/react/components/connect-modal) | Standalone wallet selection modal |
|
|
157
|
+
| [DAppKitProvider](/dapp-kit/react/dapp-kit-provider) | Context provider for hooks |
|
|
158
|
+
|
|
159
|
+
## Example Application
|
|
160
|
+
|
|
161
|
+
See the complete
|
|
162
|
+
[React example](https://github.com/MystenLabs/ts-sdks/tree/main/packages/dapp-kit-next/examples/react/simple)
|
|
163
|
+
on GitHub.
|
|
164
|
+
|
|
165
|
+
## Next Steps
|
|
166
|
+
|
|
167
|
+
- [DAppKitProvider](/dapp-kit/react/dapp-kit-provider) - Provider configuration
|
|
168
|
+
- [Hooks Reference](/dapp-kit/react/hooks) - All available hooks
|
|
169
|
+
- [Components](/dapp-kit/react/components) - UI components
|
|
170
|
+
- [Theming](/dapp-kit/theming) - Customize appearance
|
|
@@ -0,0 +1,188 @@
|
|
|
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"></script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<div>
|
|
47
|
+
<h1>My Sui dApp</h1>
|
|
48
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 4. Access Connection State
|
|
54
|
+
|
|
55
|
+
Use `@nanostores/vue` for reactive state:
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<script setup lang="ts">
|
|
59
|
+
const connection = useStore(dAppKit.stores.$connection);
|
|
60
|
+
const network = useStore(dAppKit.stores.$currentNetwork);
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<template>
|
|
64
|
+
<div>
|
|
65
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
66
|
+
|
|
67
|
+
<div v-if="connection.account">
|
|
68
|
+
<p>Wallet: {{ connection.wallet?.name }}</p>
|
|
69
|
+
<p>Address: {{ connection.account.address }}</p>
|
|
70
|
+
<p>Network: {{ network }}</p>
|
|
71
|
+
</div>
|
|
72
|
+
<p v-else>Connect your wallet to get started</p>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 5. Execute Transactions
|
|
78
|
+
|
|
79
|
+
```vue
|
|
80
|
+
<script setup lang="ts">
|
|
81
|
+
const connection = useStore(dAppKit.stores.$connection);
|
|
82
|
+
|
|
83
|
+
async function handleTransfer() {
|
|
84
|
+
const tx = new Transaction();
|
|
85
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], connection.value.account!.address);
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
89
|
+
|
|
90
|
+
if (result.FailedTransaction) {
|
|
91
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
alert(`Transaction: ${result.Transaction.digest}`);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error('Transaction failed:', error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<template>
|
|
102
|
+
<div>
|
|
103
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
104
|
+
|
|
105
|
+
<button v-if="connection.account" @click="handleTransfer">Send Transaction</button>
|
|
106
|
+
</div>
|
|
107
|
+
</template>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Complete Example
|
|
111
|
+
|
|
112
|
+
```vue
|
|
113
|
+
<script setup lang="ts">
|
|
114
|
+
const connection = useStore(dAppKit.stores.$connection);
|
|
115
|
+
const network = useStore(dAppKit.stores.$currentNetwork);
|
|
116
|
+
|
|
117
|
+
async function handleTransfer() {
|
|
118
|
+
if (!connection.value.account) return;
|
|
119
|
+
|
|
120
|
+
const tx = new Transaction();
|
|
121
|
+
tx.transferObjects([coinWithBalance({ balance: 1_000_000 })], connection.value.account.address);
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction: tx });
|
|
125
|
+
|
|
126
|
+
if (result.FailedTransaction) {
|
|
127
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
alert(`Transaction successful: ${result.Transaction.digest}`);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error('Transaction failed:', error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
</script>
|
|
136
|
+
|
|
137
|
+
<template>
|
|
138
|
+
<div class="app">
|
|
139
|
+
<h1>My Sui dApp</h1>
|
|
140
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
141
|
+
|
|
142
|
+
<div v-if="connection.account" class="wallet-info">
|
|
143
|
+
<p>Wallet: {{ connection.wallet?.name }}</p>
|
|
144
|
+
<p>Address: {{ connection.account.address }}</p>
|
|
145
|
+
<p>Network: {{ network }}</p>
|
|
146
|
+
<button @click="handleTransfer">Send Test Transaction</button>
|
|
147
|
+
</div>
|
|
148
|
+
<p v-else>Connect your wallet to get started</p>
|
|
149
|
+
</div>
|
|
150
|
+
</template>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Web Components
|
|
154
|
+
|
|
155
|
+
Vue works with dApp Kit's Web Components through property binding:
|
|
156
|
+
|
|
157
|
+
| Component | Usage |
|
|
158
|
+
| -------------- | ---------------------------------------------------------------------- |
|
|
159
|
+
| Connect Button | `<mysten-dapp-kit-connect-button :instance="dAppKit" />` |
|
|
160
|
+
| Connect Modal | `<mysten-dapp-kit-connect-modal :instance="dAppKit" :open="isOpen" />` |
|
|
161
|
+
|
|
162
|
+
See [Web Components](/dapp-kit/web-components/connect-button) for full documentation.
|
|
163
|
+
|
|
164
|
+
## Available Stores
|
|
165
|
+
|
|
166
|
+
Access these stores via `dAppKit.stores`:
|
|
167
|
+
|
|
168
|
+
| Store | Description |
|
|
169
|
+
| ----------------- | ------------------------------------------------- |
|
|
170
|
+
| `$connection` | Connection state with wallet, account, and status |
|
|
171
|
+
| `$currentNetwork` | Current network string |
|
|
172
|
+
| `$currentClient` | SuiClient for current network |
|
|
173
|
+
| `$wallets` | List of available wallets |
|
|
174
|
+
|
|
175
|
+
See [State Management](/dapp-kit/state) for full documentation.
|
|
176
|
+
|
|
177
|
+
## Example Application
|
|
178
|
+
|
|
179
|
+
See the complete
|
|
180
|
+
[Vue example](https://github.com/MystenLabs/ts-sdks/tree/main/packages/dapp-kit-next/examples/vue/simple)
|
|
181
|
+
on GitHub.
|
|
182
|
+
|
|
183
|
+
## Next Steps
|
|
184
|
+
|
|
185
|
+
- [Web Components](/dapp-kit/web-components/connect-button) - Component documentation
|
|
186
|
+
- [State Management](/dapp-kit/state) - Store details
|
|
187
|
+
- [Actions](/dapp-kit/actions/connect-wallet) - All available actions
|
|
188
|
+
- [Theming](/dapp-kit/theming) - Customize appearance
|
package/docs/index.md
ADDED
|
@@ -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
|
|
6
|
+
> `@mysten/dapp-kit` package, check out our [Migration Guide](/sui/migrations/sui-2.0/dapp-kit) to
|
|
7
|
+
> upgrade to the new 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
|
|
69
|
+
> RPC API and 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,34 @@
|
|
|
1
|
+
# dApp Kit
|
|
2
|
+
|
|
3
|
+
> Build Sui dApps with @mysten/dapp-kit-core and @mysten/dapp-kit-react
|
|
4
|
+
|
|
5
|
+
- [Sui dApp Kit](./index.md): Build Sui dApps with framework-agnostic core and React bindings
|
|
6
|
+
- [@mysten/create-dapp](./getting-started/create-dapp.md): Create a Sui dApp with one command
|
|
7
|
+
- [React](./getting-started/react.md): Set up dApp Kit in a React application
|
|
8
|
+
- [Next.js](./getting-started/next-js.md): Set up dApp Kit in a Next.js application
|
|
9
|
+
- [Vue](./getting-started/vue.md): Set up dApp Kit in a Vue application
|
|
10
|
+
- [DApp Kit Instance](./dapp-kit-instance.md): Create and configure a DAppKit instance for wallet
|
|
11
|
+
and client management
|
|
12
|
+
- [State](./state.md): Access and subscribe to wallet connection state in dApp Kit
|
|
13
|
+
- [Connect Wallet](./actions/connect-wallet.md): Programmatically connect to a Sui wallet
|
|
14
|
+
- [Disconnect Wallet](./actions/disconnect-wallet.md): Programmatically disconnect from a Sui wallet
|
|
15
|
+
- [Sign and Execute Transaction](./actions/sign-and-execute-transaction.md): Sign and execute a
|
|
16
|
+
transaction using the connected wallet
|
|
17
|
+
- [Sign Personal Message](./actions/sign-personal-message.md): Sign an arbitrary message with the
|
|
18
|
+
connected wallet
|
|
19
|
+
- [Sign Transaction](./actions/sign-transaction.md): Sign a transaction without executing it
|
|
20
|
+
- [Switch Account](./actions/switch-account.md): Switch the active account in the connected wallet
|
|
21
|
+
- [Switch Network](./actions/switch-network.md): Switch the active network for the dApp Kit instance
|
|
22
|
+
- [DAppKitProvider](./react/dapp-kit-provider.md): React context provider for dApp Kit configuration
|
|
23
|
+
- [React Hooks](./react/hooks/index.md): React hooks for accessing dApp Kit state and actions
|
|
24
|
+
- [useDAppKit](./react/hooks/use-dapp-kit.md): React hook to access the full dApp Kit instance
|
|
25
|
+
- [React Components](./react/components/index.md): Pre-built React UI components for wallet
|
|
26
|
+
interaction
|
|
27
|
+
- [Connect Button](./react/components/connect-button.md): React button component for wallet
|
|
28
|
+
connection
|
|
29
|
+
- [Connect Modal](./react/components/connect-modal.md): React modal component for wallet selection
|
|
30
|
+
- [Connect Button](./web-components/connect-button.md): Framework-agnostic web component for wallet
|
|
31
|
+
connection
|
|
32
|
+
- [Connect Modal](./web-components/connect-modal.md): Framework-agnostic web component for wallet
|
|
33
|
+
selection
|
|
34
|
+
- [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).
|