@mysten/dapp-kit-react 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/index.d.mts +9 -9
  2. package/dist/index.d.mts.map +1 -1
  3. package/dist/ui.d.mts.map +1 -1
  4. package/package.json +3 -5
  5. package/docs/actions/connect-wallet.md +0 -68
  6. package/docs/actions/disconnect-wallet.md +0 -37
  7. package/docs/actions/sign-and-execute-transaction.md +0 -95
  8. package/docs/actions/sign-personal-message.md +0 -57
  9. package/docs/actions/sign-transaction.md +0 -64
  10. package/docs/actions/switch-account.md +0 -36
  11. package/docs/actions/switch-network.md +0 -36
  12. package/docs/dapp-kit-instance.md +0 -163
  13. package/docs/getting-started/create-dapp.md +0 -151
  14. package/docs/getting-started/next-js.md +0 -162
  15. package/docs/getting-started/react.md +0 -170
  16. package/docs/getting-started/vue.md +0 -188
  17. package/docs/index.md +0 -70
  18. package/docs/llms-index.md +0 -34
  19. package/docs/react/components/connect-button.md +0 -42
  20. package/docs/react/components/connect-modal.md +0 -51
  21. package/docs/react/components/index.md +0 -13
  22. package/docs/react/dapp-kit-provider.md +0 -86
  23. package/docs/react/hooks/index.md +0 -25
  24. package/docs/react/hooks/use-current-account.md +0 -33
  25. package/docs/react/hooks/use-current-client.md +0 -36
  26. package/docs/react/hooks/use-current-network.md +0 -28
  27. package/docs/react/hooks/use-current-wallet.md +0 -36
  28. package/docs/react/hooks/use-dapp-kit.md +0 -100
  29. package/docs/react/hooks/use-wallet-connection.md +0 -48
  30. package/docs/react/hooks/use-wallets.md +0 -33
  31. package/docs/state.md +0 -168
  32. package/docs/theming.md +0 -196
  33. package/docs/web-components/connect-button.md +0 -87
  34. package/docs/web-components/connect-modal.md +0 -176
@@ -1,151 +0,0 @@
1
- # @mysten/create-dapp
2
-
3
- > Create a Sui dApp with one command
4
-
5
- `@mysten/create-dapp` is a CLI tool that scaffolds a complete Sui dApp project with best practices
6
- built in.
7
-
8
- ## Quick Start
9
-
10
- ```sh npm2yarn
11
- npm create @mysten/dapp
12
- ```
13
-
14
- The CLI prompts you to choose a template and project name, then creates a ready-to-run project.
15
-
16
- ## Templates
17
-
18
- ### react-client-dapp
19
-
20
- A basic React dApp that demonstrates wallet connection and fetching owned objects:
21
-
22
- - Wallet connection with `ConnectButton`
23
- - Display connected wallet address
24
- - List objects owned by the connected wallet
25
- - Clean, modern UI with Tailwind CSS
26
-
27
- ### react-e2e-counter
28
-
29
- A complete end-to-end example with Move smart contract integration:
30
-
31
- - Move counter contract in `move/counter/`
32
- - TypeScript bindings generated with `@mysten/codegen`
33
- - Create, increment, and reset counters
34
- - MVR (Move Registry) name resolution for package IDs
35
- - Full transaction signing and execution
36
-
37
- ## Tech Stack
38
-
39
- Both templates include:
40
-
41
- - [React](https://react.dev/) - UI framework
42
- - [TypeScript](https://www.typescriptlang.org/) - Type safety
43
- - [Vite](https://vitejs.dev/) - Fast build tooling
44
- - [Tailwind CSS v4](https://tailwindcss.com/) - Utility-first styling
45
- - [Lucide React](https://lucide.dev/) - Modern icons
46
- - [`@mysten/dapp-kit-react`](/dapp-kit) - Wallet connection and blockchain interaction
47
- - [pnpm](https://pnpm.io/) - Package management
48
-
49
- The e2e-counter template also includes:
50
-
51
- - [`@mysten/codegen`](/codegen) - Generate TypeScript from Move code
52
-
53
- ## Project Structure
54
-
55
- ### react-client-dapp
56
-
57
- ```
58
- src/
59
- ├── components/ui/ # Reusable UI components (Card)
60
- ├── lib/utils.ts # Utility functions
61
- ├── App.tsx # Main application
62
- ├── WalletStatus.tsx # Wallet connection display
63
- ├── OwnedObjects.tsx # Object list component
64
- ├── dApp-kit.ts # dApp Kit configuration
65
- └── index.css # Tailwind CSS theme
66
- ```
67
-
68
- ### react-e2e-counter
69
-
70
- ```
71
- src/
72
- ├── components/ui/ # UI components (Button, Card)
73
- ├── contracts/ # Generated TypeScript bindings
74
- ├── lib/utils.ts # Utility functions
75
- ├── App.tsx # Main application
76
- ├── Counter.tsx # Counter display and controls
77
- ├── CreateCounter.tsx # Counter creation
78
- ├── dApp-kit.ts # dApp Kit configuration
79
- ├── constants.ts # Package IDs per network
80
- └── index.css # Tailwind CSS theme
81
- move/
82
- └── counter/ # Move smart contract
83
- ```
84
-
85
- ## Using the e2e-counter Template
86
-
87
- ### 1. Deploy the Move Contract
88
-
89
- First, install the [Sui CLI](https://docs.sui.io/build/install) and set up testnet:
90
-
91
- ```bash
92
- sui client new-env --alias testnet --rpc https://fullnode.testnet.sui.io:443
93
- sui client switch --env testnet
94
- ```
95
-
96
- Get testnet SUI from the [faucet](https://faucet.sui.io), then publish:
97
-
98
- ```bash
99
- cd move
100
- sui client publish --gas-budget 100000000 counter
101
- ```
102
-
103
- ### 2. Configure the Package ID
104
-
105
- Copy the `packageId` from the publish output to `src/constants.ts`:
106
-
107
- ```ts
108
-
109
- ```
110
-
111
- ### 3. Generate TypeScript Bindings
112
-
113
- ```bash
114
- pnpm codegen
115
- ```
116
-
117
- This generates type-safe functions in `src/contracts/` for interacting with your Move modules.
118
-
119
- ### 4. Start Development
120
-
121
- ```bash
122
- pnpm install
123
- pnpm dev
124
- ```
125
-
126
- ## Customizing the UI
127
-
128
- The templates use [Tailwind CSS v4](https://tailwindcss.com/docs) with
129
- [shadcn/ui](https://ui.shadcn.com/)-style components. The UI components in `src/components/ui/` can
130
- be customized or extended.
131
-
132
- To add more components, copy them from the
133
- [shadcn/ui components](https://ui.shadcn.com/docs/components) documentation and adapt them to your
134
- project.
135
-
136
- Theme variables are defined in `src/index.css` using Tailwind's `@theme` directive.
137
-
138
- ## CLI Options
139
-
140
- You can skip prompts with command-line flags:
141
-
142
- ```bash
143
- # Create with specific template
144
- npm create @mysten/dapp -- -t react-e2e-counter
145
-
146
- # Create with specific name
147
- npm create @mysten/dapp -- -n my-app
148
-
149
- # Create with both
150
- npm create @mysten/dapp -- -t react-client-dapp -n my-app
151
- ```
@@ -1,162 +0,0 @@
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
@@ -1,170 +0,0 @@
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
@@ -1,188 +0,0 @@
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