@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.
- package/dist/index.d.mts +9 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/ui.d.mts.map +1 -1
- package/package.json +3 -5
- package/docs/actions/connect-wallet.md +0 -68
- package/docs/actions/disconnect-wallet.md +0 -37
- package/docs/actions/sign-and-execute-transaction.md +0 -95
- package/docs/actions/sign-personal-message.md +0 -57
- package/docs/actions/sign-transaction.md +0 -64
- package/docs/actions/switch-account.md +0 -36
- package/docs/actions/switch-network.md +0 -36
- package/docs/dapp-kit-instance.md +0 -163
- package/docs/getting-started/create-dapp.md +0 -151
- package/docs/getting-started/next-js.md +0 -162
- package/docs/getting-started/react.md +0 -170
- package/docs/getting-started/vue.md +0 -188
- package/docs/index.md +0 -70
- package/docs/llms-index.md +0 -34
- package/docs/react/components/connect-button.md +0 -42
- package/docs/react/components/connect-modal.md +0 -51
- package/docs/react/components/index.md +0 -13
- package/docs/react/dapp-kit-provider.md +0 -86
- package/docs/react/hooks/index.md +0 -25
- package/docs/react/hooks/use-current-account.md +0 -33
- package/docs/react/hooks/use-current-client.md +0 -36
- package/docs/react/hooks/use-current-network.md +0 -28
- package/docs/react/hooks/use-current-wallet.md +0 -36
- package/docs/react/hooks/use-dapp-kit.md +0 -100
- package/docs/react/hooks/use-wallet-connection.md +0 -48
- package/docs/react/hooks/use-wallets.md +0 -33
- package/docs/state.md +0 -168
- package/docs/theming.md +0 -196
- package/docs/web-components/connect-button.md +0 -87
- package/docs/web-components/connect-modal.md +0 -176
package/docs/index.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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`.
|
package/docs/llms-index.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
|
@@ -1,42 +0,0 @@
|
|
|
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).
|
|
@@ -1,51 +0,0 @@
|
|
|
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).
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1,86 +0,0 @@
|
|
|
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).
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# useCurrentAccount
|
|
2
|
-
|
|
3
|
-
> React hook to get the current wallet account
|
|
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
|
-
```
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# useCurrentClient
|
|
2
|
-
|
|
3
|
-
> React hook to get the current Sui client instance
|
|
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,
|
|
9
|
-
> the dApp Kit supports any client that implements the Sui core API, making it flexible for
|
|
10
|
-
> different 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
|
-
```
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# useCurrentNetwork
|
|
2
|
-
|
|
3
|
-
> React hook to get the current network
|
|
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
|
-
```
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# useCurrentWallet
|
|
2
|
-
|
|
3
|
-
> React hook to get the current wallet connection
|
|
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
|
-
```
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# useDAppKit
|
|
2
|
-
|
|
3
|
-
> React hook to access the full dApp Kit instance
|
|
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
|
-
```
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# useWalletConnection
|
|
2
|
-
|
|
3
|
-
> React hook to manage wallet connection and disconnection
|
|
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
|
-
```
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# useWallets
|
|
2
|
-
|
|
3
|
-
> React hook to list available wallets
|
|
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
|
-
```
|