@mysten/dapp-kit-react 2.0.2 → 2.1.0
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/dist/index.d.mts +1 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/ui.d.mts +3 -3
- package/dist/ui.d.mts.map +1 -1
- package/docs/actions/connect-wallet.md +69 -0
- package/docs/actions/disconnect-wallet.md +39 -0
- package/docs/actions/sign-and-execute-transaction.md +96 -0
- package/docs/actions/sign-personal-message.md +58 -0
- package/docs/actions/sign-transaction.md +65 -0
- package/docs/actions/switch-account.md +37 -0
- package/docs/actions/switch-network.md +37 -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 +163 -0
- package/docs/getting-started/react.md +172 -0
- package/docs/getting-started/vue.md +193 -0
- package/docs/index.md +70 -0
- package/docs/llms-index.md +33 -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 +26 -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 +169 -0
- package/docs/theming.md +196 -0
- package/docs/web-components/connect-button.md +89 -0
- package/docs/web-components/connect-modal.md +177 -0
- package/package.json +5 -5
package/docs/index.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Sui dApp Kit
|
|
2
|
+
|
|
3
|
+
> Build Sui apps 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
|
+
```npm
|
|
38
|
+
npm i @mysten/dapp-kit-react @mysten/sui
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Vanilla JavaScript and other frameworks
|
|
42
|
+
|
|
43
|
+
```npm
|
|
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,33 @@
|
|
|
1
|
+
# dApp Kit
|
|
2
|
+
> Build Sui dApps with @mysten/dapp-kit-core and @mysten/dapp-kit-react
|
|
3
|
+
|
|
4
|
+
- [Sui dApp Kit](..md): Build Sui apps with framework-agnostic core and React bindings.
|
|
5
|
+
- [@mysten/create-dapp](./getting-started/create-dapp.md): Create a Sui app with one command using the create-dapp CLI scaffolding tool.
|
|
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 using the dApp Kit connectWallet action.
|
|
12
|
+
- [Disconnect Wallet](./actions/disconnect-wallet.md): Programmatically disconnect from a Sui wallet using the dApp Kit disconnectWallet action.
|
|
13
|
+
- [Sign and Execute Transaction](./actions/sign-and-execute-transaction.md): Sign and execute a transaction on the Sui network using the connected wallet.
|
|
14
|
+
- [Sign Personal Message](./actions/sign-personal-message.md): Sign an arbitrary message with the connected wallet for authentication or proof of ownership.
|
|
15
|
+
- [Sign Transaction](./actions/sign-transaction.md): Sign a Sui transaction without executing it for deferred or multi-signature scenarios.
|
|
16
|
+
- [Switch Account](./actions/switch-account.md): Switch the active account in the connected wallet using the dApp Kit switchAccount action.
|
|
17
|
+
- [Switch Network](./actions/switch-network.md): Switch the active network for the dApp Kit instance between mainnet, testnet, and other networks.
|
|
18
|
+
- [DAppKitProvider](./react/dapp-kit-provider.md): React context provider that makes dApp Kit available throughout your application.
|
|
19
|
+
- [React Hooks](./react/hooks.md): React hooks for accessing dApp Kit state and actions in Sui applications.
|
|
20
|
+
- [useDAppKit](./react/hooks/use-dapp-kit.md): React hook to access the full dApp Kit instance for calling actions directly.
|
|
21
|
+
- [useCurrentAccount](./react/hooks/use-current-account.md): React hook to get the currently selected wallet account in a Sui dApp.
|
|
22
|
+
- [useCurrentClient](./react/hooks/use-current-client.md): React hook to get the current Sui client instance for the active network.
|
|
23
|
+
- [useCurrentNetwork](./react/hooks/use-current-network.md): React hook to get the currently selected Sui network in dApp Kit.
|
|
24
|
+
- [useCurrentWallet](./react/hooks/use-current-wallet.md): React hook to get the currently connected wallet in a Sui dApp.
|
|
25
|
+
- [useWalletConnection](./react/hooks/use-wallet-connection.md): React hook to manage wallet connection status and information in a Sui dApp.
|
|
26
|
+
- [useWallets](./react/hooks/use-wallets.md): React hook to list all available Sui wallets detected by dApp Kit.
|
|
27
|
+
- [React Components](./react/components.md): Pre-built React UI components for wallet interaction in Sui dApps.
|
|
28
|
+
- [Connect Button](./react/components/connect-button.md): React button component for connecting and disconnecting Sui wallets.
|
|
29
|
+
- [Connect Modal](./react/components/connect-modal.md): React modal component for selecting and connecting to a Sui wallet.
|
|
30
|
+
- [Connect Button](./web-components/connect-button.md): Framework-agnostic web component providing a complete wallet connection UI for Sui dApps.
|
|
31
|
+
- [Connect Modal](./web-components/connect-modal.md): Framework-agnostic web component for wallet selection and connection in Sui dApps.
|
|
32
|
+
- [Theming](./theming.md): Customize the appearance of dApp Kit UI components.
|
|
33
|
+
- [Sui dApp Kit (Legacy)](./legacy.md): Legacy dApp Kit API reference for the deprecated @mysten/dapp-kit package using JSON RPC.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Connect Button
|
|
2
|
+
|
|
3
|
+
> React button component for connecting and disconnecting Sui wallets.
|
|
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 selecting and connecting to a Sui wallet.
|
|
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 in Sui dApps.
|
|
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 that makes dApp Kit available throughout your application.
|
|
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,26 @@
|
|
|
1
|
+
# React Hooks
|
|
2
|
+
|
|
3
|
+
> React hooks for accessing dApp Kit state and actions in Sui applications.
|
|
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
|
|
10
|
+
> error.
|
|
11
|
+
|
|
12
|
+
## Available hooks
|
|
13
|
+
|
|
14
|
+
- [`useDAppKit`](/dapp-kit/react/hooks/use-dapp-kit) - Access the dApp Kit instance for calling
|
|
15
|
+
actions directly
|
|
16
|
+
- [`useCurrentAccount`](/dapp-kit/react/hooks/use-current-account) - Get the currently selected
|
|
17
|
+
account
|
|
18
|
+
- [`useCurrentClient`](/dapp-kit/react/hooks/use-current-client) - Get the blockchain client for the
|
|
19
|
+
current network
|
|
20
|
+
- [`useCurrentNetwork`](/dapp-kit/react/hooks/use-current-network) - Get the currently selected
|
|
21
|
+
network
|
|
22
|
+
- [`useCurrentWallet`](/dapp-kit/react/hooks/use-current-wallet) - Get the currently connected
|
|
23
|
+
wallet
|
|
24
|
+
- [`useWalletConnection`](/dapp-kit/react/hooks/use-wallet-connection) - Get wallet connection
|
|
25
|
+
status and actions
|
|
26
|
+
- [`useWallets`](/dapp-kit/react/hooks/use-wallets) - Get all available wallets
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# useCurrentAccount
|
|
2
|
+
|
|
3
|
+
> React hook to get the currently selected wallet account in a Sui dApp.
|
|
4
|
+
|
|
5
|
+
The `useCurrentAccount` hook provides access to the currently selected account.
|
|
6
|
+
|
|
7
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
8
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
|
|
14
|
+
const account = useCurrentAccount();
|
|
15
|
+
|
|
16
|
+
if (!account) {
|
|
17
|
+
return <div>No account selected</div>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<p>Address: {account.address}</p>
|
|
23
|
+
<p>Label: {account.label}</p>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Return value
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
UiWalletAccount | null;
|
|
33
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# useCurrentClient
|
|
2
|
+
|
|
3
|
+
> React hook to get the current Sui client instance for the active network.
|
|
4
|
+
|
|
5
|
+
The `useCurrentClient` hook provides access to the blockchain client instance for the current
|
|
6
|
+
network.
|
|
7
|
+
|
|
8
|
+
> **Note:** By default, this returns a `SuiClient` instance when using the standard setup. However, the dApp
|
|
9
|
+
> Kit supports any client that implements the Sui core API, making it flexible for different
|
|
10
|
+
> blockchain implementations.
|
|
11
|
+
|
|
12
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
13
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
|
|
19
|
+
const client = useCurrentClient();
|
|
20
|
+
|
|
21
|
+
const handleQuery = async () => {
|
|
22
|
+
const balance = await client.getBalance({
|
|
23
|
+
owner: '0x...',
|
|
24
|
+
});
|
|
25
|
+
console.log(balance);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return <button onClick={handleQuery}>Check Balance</button>;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Return value
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
SuiClient;
|
|
36
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# useCurrentNetwork
|
|
2
|
+
|
|
3
|
+
> React hook to get the currently selected Sui network in dApp Kit.
|
|
4
|
+
|
|
5
|
+
The `useCurrentNetwork` hook provides access to the currently selected network.
|
|
6
|
+
|
|
7
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
8
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
|
|
14
|
+
const network = useCurrentNetwork();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
<p>Current network: {network}</p>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Return value
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
string;
|
|
28
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# useCurrentWallet
|
|
2
|
+
|
|
3
|
+
> React hook to get the currently connected wallet in a Sui dApp.
|
|
4
|
+
|
|
5
|
+
The `useCurrentWallet` hook provides access to the currently connected wallet.
|
|
6
|
+
|
|
7
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
8
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
|
|
14
|
+
const wallet = useCurrentWallet();
|
|
15
|
+
|
|
16
|
+
if (!wallet) {
|
|
17
|
+
return <div>No wallet connected</div>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<p>Wallet: {wallet.name}</p>
|
|
23
|
+
<p>
|
|
24
|
+
Icon: <img src={wallet.icon} alt={wallet.name} />
|
|
25
|
+
</p>
|
|
26
|
+
<p>Accounts: {wallet.accounts.length}</p>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Return value
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
UiWallet | null;
|
|
36
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# useDAppKit
|
|
2
|
+
|
|
3
|
+
> React hook to access the full dApp Kit instance for calling actions directly.
|
|
4
|
+
|
|
5
|
+
The `useDAppKit` hook provides direct access to the dApp Kit instance within React components,
|
|
6
|
+
enabling you to call actions and access the underlying functionality.
|
|
7
|
+
|
|
8
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
9
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
|
|
15
|
+
const dAppKit = useDAppKit();
|
|
16
|
+
|
|
17
|
+
async function handleConnect() {
|
|
18
|
+
try {
|
|
19
|
+
await dAppKit.connectWallet({ wallet });
|
|
20
|
+
console.log('Connected successfully');
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('Connection failed:', error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return <button onClick={handleConnect}>Connect Wallet</button>;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Return value
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
{
|
|
34
|
+
// Actions
|
|
35
|
+
connectWallet: (args: { wallet: UiWallet; account?: UiWalletAccount }) => Promise<{ accounts: UiWalletAccount[]; }>;
|
|
36
|
+
disconnectWallet: () => Promise<void>;
|
|
37
|
+
switchAccount: (args: { account: UiWalletAccount }) => Promise<void>;
|
|
38
|
+
switchNetwork: (network: string) => void;
|
|
39
|
+
signTransaction: (args: { transaction: Transaction | string; signal?: AbortSignal }) => Promise<SignedTransaction>;
|
|
40
|
+
signAndExecuteTransaction: (args: { transaction: Transaction | string; signal?: AbortSignal }) => Promise<TransactionResult>;
|
|
41
|
+
signPersonalMessage: (args: { message: Uint8Array }) => Promise<SignedPersonalMessage>;
|
|
42
|
+
|
|
43
|
+
// Properties
|
|
44
|
+
networks: string[];
|
|
45
|
+
stores: {
|
|
46
|
+
$wallets: DAppKitStores['$compatibleWallets'];
|
|
47
|
+
$connection: DAppKitStores['$connection'];
|
|
48
|
+
$currentNetwork: ReadableAtom<TNetworks[number]>;
|
|
49
|
+
$currentClient: ReadableAtom<Client>;
|
|
50
|
+
};
|
|
51
|
+
getClient: (network?: string) => Client;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Examples
|
|
56
|
+
|
|
57
|
+
### Transaction execution
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
|
|
61
|
+
const dAppKit = useDAppKit();
|
|
62
|
+
|
|
63
|
+
async function handleTransfer() {
|
|
64
|
+
const tx = new Transaction();
|
|
65
|
+
tx.transferObjects([tx.object('0x123...')], '0xrecipient...');
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
69
|
+
transaction: tx,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (result.FailedTransaction) {
|
|
73
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('Transaction failed:', error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return <button onClick={handleTransfer}>Transfer</button>;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Subscribing to state changes
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
|
|
90
|
+
const dAppKit = useDAppKit();
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
// Subscribe directly to connection store changes
|
|
93
|
+
const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
|
|
94
|
+
console.log('Connection status:', connection.status);
|
|
95
|
+
});
|
|
96
|
+
return unsubscribe;
|
|
97
|
+
}, [dAppKit]);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# useWalletConnection
|
|
2
|
+
|
|
3
|
+
> React hook to manage wallet connection status and information in a Sui dApp.
|
|
4
|
+
|
|
5
|
+
The `useWalletConnection` hook provides access to the current wallet connection status and
|
|
6
|
+
information.
|
|
7
|
+
|
|
8
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
9
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
|
|
15
|
+
const connection = useWalletConnection();
|
|
16
|
+
|
|
17
|
+
if (connection.status === 'disconnected') {
|
|
18
|
+
return <div>Please connect your wallet</div>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (connection.status === 'connecting') {
|
|
22
|
+
return <div>Connecting...</div>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// status === 'connected'
|
|
26
|
+
return (
|
|
27
|
+
<div>
|
|
28
|
+
<p>Connected to: {connection.wallet.name}</p>
|
|
29
|
+
<p>Address: {connection.account.address}</p>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Return value
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
{
|
|
39
|
+
status: 'disconnected' | 'connecting' | 'reconnecting' | 'connected';
|
|
40
|
+
wallet: UiWallet | null;
|
|
41
|
+
account: UiWalletAccount | null;
|
|
42
|
+
supportedIntents: string[];
|
|
43
|
+
isConnected: boolean;
|
|
44
|
+
isConnecting: boolean;
|
|
45
|
+
isReconnecting: boolean;
|
|
46
|
+
isDisconnected: boolean;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# useWallets
|
|
2
|
+
|
|
3
|
+
> React hook to list all available Sui wallets detected by dApp Kit.
|
|
4
|
+
|
|
5
|
+
The `useWallets` hook provides access to all available wallets.
|
|
6
|
+
|
|
7
|
+
> **Warning:** All dApp Kit hooks must be used within components that are descendants of
|
|
8
|
+
> [`DAppKitProvider`](../dapp-kit-provider). Using them outside will result in an error.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
|
|
14
|
+
const wallets = useWallets();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
{wallets.map((wallet) => (
|
|
19
|
+
<div key={wallet.name}>
|
|
20
|
+
<img src={wallet.icon} alt={wallet.name} />
|
|
21
|
+
<span>{wallet.name}</span>
|
|
22
|
+
</div>
|
|
23
|
+
))}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Return value
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
UiWallet[]
|
|
33
|
+
```
|