@mysten/docs 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/bcs/index.md +358 -0
- package/dist/bcs/llms-index.md +4 -0
- package/dist/codegen/index.md +441 -0
- package/dist/codegen/llms-index.md +4 -0
- package/dist/dapp-kit/actions/connect-wallet.md +69 -0
- package/dist/dapp-kit/actions/disconnect-wallet.md +38 -0
- package/dist/dapp-kit/actions/sign-and-execute-transaction.md +96 -0
- package/dist/dapp-kit/actions/sign-personal-message.md +58 -0
- package/dist/dapp-kit/actions/sign-transaction.md +65 -0
- package/dist/dapp-kit/actions/switch-account.md +37 -0
- package/dist/dapp-kit/actions/switch-network.md +37 -0
- package/dist/dapp-kit/dapp-kit-instance.md +162 -0
- package/dist/dapp-kit/getting-started/create-dapp.md +151 -0
- package/dist/dapp-kit/getting-started/next-js.md +162 -0
- package/dist/dapp-kit/getting-started/react.md +172 -0
- package/dist/dapp-kit/getting-started/vue.md +193 -0
- package/dist/dapp-kit/index.md +70 -0
- package/dist/dapp-kit/llms-index.md +26 -0
- package/dist/dapp-kit/react/components/connect-button.md +42 -0
- package/dist/dapp-kit/react/components/connect-modal.md +51 -0
- package/dist/dapp-kit/react/components/index.md +13 -0
- package/dist/dapp-kit/react/dapp-kit-provider.md +86 -0
- package/dist/dapp-kit/react/hooks/index.md +25 -0
- package/dist/dapp-kit/react/hooks/use-current-account.md +33 -0
- package/dist/dapp-kit/react/hooks/use-current-client.md +36 -0
- package/dist/dapp-kit/react/hooks/use-current-network.md +28 -0
- package/dist/dapp-kit/react/hooks/use-current-wallet.md +36 -0
- package/dist/dapp-kit/react/hooks/use-dapp-kit.md +100 -0
- package/dist/dapp-kit/react/hooks/use-wallet-connection.md +48 -0
- package/dist/dapp-kit/react/hooks/use-wallets.md +33 -0
- package/dist/dapp-kit/state.md +169 -0
- package/dist/dapp-kit/theming.md +196 -0
- package/dist/dapp-kit/web-components/connect-button.md +89 -0
- package/dist/dapp-kit/web-components/connect-modal.md +177 -0
- package/dist/kiosk/advanced-examples.md +101 -0
- package/dist/kiosk/from-v1.md +320 -0
- package/dist/kiosk/index.md +22 -0
- package/dist/kiosk/kiosk-client/introduction.md +52 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/examples.md +119 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/managing.md +235 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/purchasing.md +110 -0
- package/dist/kiosk/kiosk-client/querying.md +237 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
- package/dist/kiosk/llms-index.md +8 -0
- package/dist/llms-index.md +125 -0
- package/dist/payment-kit/getting-started.md +256 -0
- package/dist/payment-kit/index.md +132 -0
- package/dist/payment-kit/llms-index.md +8 -0
- package/dist/payment-kit/payment-kit-sdk.md +747 -0
- package/dist/payment-kit/payment-processing.md +372 -0
- package/dist/payment-kit/registry-management.md +529 -0
- package/dist/seal/index.md +85 -0
- package/dist/seal/llms-index.md +4 -0
- package/dist/slush-wallet/dapp.md +95 -0
- package/dist/slush-wallet/deep-linking.md +465 -0
- package/dist/slush-wallet/index.md +7 -0
- package/dist/slush-wallet/llms-index.md +6 -0
- package/dist/sui/bcs.md +134 -0
- package/dist/sui/clients/core.md +606 -0
- package/dist/sui/clients/graphql.md +101 -0
- package/dist/sui/clients/grpc.md +155 -0
- package/dist/sui/clients/index.md +95 -0
- package/dist/sui/clients/json-rpc.md +239 -0
- package/dist/sui/cryptography/keypairs.md +267 -0
- package/dist/sui/cryptography/multisig.md +194 -0
- package/dist/sui/cryptography/passkey.md +111 -0
- package/dist/sui/cryptography/webcrypto-signer.md +81 -0
- package/dist/sui/executors.md +148 -0
- package/dist/sui/faucet.md +26 -0
- package/dist/sui/hello-sui.md +115 -0
- package/dist/sui/index.md +53 -0
- package/dist/sui/install.md +61 -0
- package/dist/sui/llm-docs.md +32 -0
- package/dist/sui/llms-index.md +44 -0
- package/dist/sui/migrations/0.38.md +58 -0
- package/dist/sui/migrations/sui-1.0.md +455 -0
- package/dist/sui/migrations/sui-2.0/agent-prompt.md +42 -0
- package/dist/sui/migrations/sui-2.0/dapp-kit.md +350 -0
- package/dist/sui/migrations/sui-2.0/deepbook-v3.md +33 -0
- package/dist/sui/migrations/sui-2.0/index.md +158 -0
- package/dist/sui/migrations/sui-2.0/json-rpc-migration.md +386 -0
- package/dist/sui/migrations/sui-2.0/kiosk.md +120 -0
- package/dist/sui/migrations/sui-2.0/sdk-maintainers.md +90 -0
- package/dist/sui/migrations/sui-2.0/seal.md +14 -0
- package/dist/sui/migrations/sui-2.0/sui.md +341 -0
- package/dist/sui/migrations/sui-2.0/suins.md +43 -0
- package/dist/sui/migrations/sui-2.0/wallet-builders.md +66 -0
- package/dist/sui/migrations/sui-2.0/walrus.md +41 -0
- package/dist/sui/migrations/sui-2.0/zksend.md +95 -0
- package/dist/sui/plugins.md +258 -0
- package/dist/sui/sdk-building.md +344 -0
- package/dist/sui/transaction-building/basics.md +299 -0
- package/dist/sui/transaction-building/gas.md +62 -0
- package/dist/sui/transaction-building/intents.md +62 -0
- package/dist/sui/transaction-building/offline.md +73 -0
- package/dist/sui/transaction-building/sponsored-transactions.md +22 -0
- package/dist/sui/utils/derived_objects.md +59 -0
- package/dist/sui/utils/index.md +52 -0
- package/dist/sui/zklogin.md +83 -0
- package/dist/walrus/index.md +527 -0
- package/dist/walrus/llms-index.md +4 -0
- package/dist/zksend/index.md +27 -0
- package/dist/zksend/link-builder.md +192 -0
- package/dist/zksend/llms-index.md +5 -0
- package/package.json +66 -0
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
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, 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 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
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# State
|
|
2
|
+
|
|
3
|
+
> Access and subscribe to wallet connection state in dApp Kit
|
|
4
|
+
|
|
5
|
+
The Sui dApp Kit SDK uses [nanostores](https://github.com/nanostores/nanostores) for state
|
|
6
|
+
management, providing a lightweight, framework-agnostic solution that works across React, Vue,
|
|
7
|
+
Vanilla JavaScript, and other frameworks.
|
|
8
|
+
|
|
9
|
+
## Available Stores
|
|
10
|
+
|
|
11
|
+
The dApp Kit exposes four reactive stores that you can subscribe to:
|
|
12
|
+
|
|
13
|
+
- **`$connection`** - Current wallet connection state
|
|
14
|
+
- **`$currentNetwork`** - Currently selected network
|
|
15
|
+
- **`$currentClient`** - Client instance for the current network
|
|
16
|
+
- **`$wallets`** - List of available wallets
|
|
17
|
+
|
|
18
|
+
## Accessing Stores
|
|
19
|
+
|
|
20
|
+
All stores are available through the `dAppKit.stores` property:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
|
|
24
|
+
const dAppKit = createDAppKit({
|
|
25
|
+
/* config */
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Access stores
|
|
29
|
+
const connection = dAppKit.stores.$connection.get();
|
|
30
|
+
const currentNetwork = dAppKit.stores.$currentNetwork.get();
|
|
31
|
+
const client = dAppKit.stores.$currentClient.get();
|
|
32
|
+
const wallets = dAppKit.stores.$wallets.get();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Subscribing to State Changes
|
|
36
|
+
|
|
37
|
+
Subscribe to any store to react to state changes:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// Subscribe to connection changes
|
|
41
|
+
const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
|
|
42
|
+
if (connection.isConnected && connection.wallet && connection.account) {
|
|
43
|
+
console.log('Connected to:', connection.wallet.name);
|
|
44
|
+
console.log('Account:', connection.account.address);
|
|
45
|
+
} else {
|
|
46
|
+
console.log('Not connected');
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Clean up subscription when done
|
|
51
|
+
unsubscribe();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Store Details
|
|
55
|
+
|
|
56
|
+
### Connection Store (`$connection`)
|
|
57
|
+
|
|
58
|
+
Contains the current wallet connection state with status flags:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const connection = dAppKit.stores.$connection.get();
|
|
62
|
+
|
|
63
|
+
// Connection has these properties:
|
|
64
|
+
// - wallet: UiWallet | null
|
|
65
|
+
// - account: UiWalletAccount | null
|
|
66
|
+
// - status: 'connected' | 'connecting' | 'reconnecting' | 'disconnected'
|
|
67
|
+
// - supportedIntents: string[]
|
|
68
|
+
// - isConnected: boolean
|
|
69
|
+
// - isConnecting: boolean
|
|
70
|
+
// - isReconnecting: boolean
|
|
71
|
+
// - isDisconnected: boolean
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Example usage:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const connection = dAppKit.stores.$connection.get();
|
|
78
|
+
|
|
79
|
+
if (connection.isConnected && connection.wallet && connection.account) {
|
|
80
|
+
console.log('Address:', connection.account.address);
|
|
81
|
+
console.log('Wallet:', connection.wallet.name);
|
|
82
|
+
console.log('Available accounts:', connection.wallet.accounts);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Current Network Store (`$currentNetwork`)
|
|
87
|
+
|
|
88
|
+
Contains the currently selected network as a string:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const currentNetwork = dAppKit.stores.$currentNetwork.get(); // 'mainnet' | 'testnet' | ...
|
|
92
|
+
|
|
93
|
+
// Subscribe to network changes
|
|
94
|
+
dAppKit.stores.$currentNetwork.subscribe((network) => {
|
|
95
|
+
console.log('Switched to network:', network);
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Note: This store is read-only. Use `dAppKit.switchNetwork()` to change networks.
|
|
100
|
+
|
|
101
|
+
### Current Client Store (`$currentClient`)
|
|
102
|
+
|
|
103
|
+
Contains the SuiClient instance for the current network:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const client = dAppKit.stores.$currentClient.get();
|
|
107
|
+
|
|
108
|
+
// Use the client to query the blockchain
|
|
109
|
+
const balance = await client.getBalance({
|
|
110
|
+
owner: '0x...',
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Note: This store automatically updates when the network changes.
|
|
115
|
+
|
|
116
|
+
### Wallets Store (`$wallets`)
|
|
117
|
+
|
|
118
|
+
Contains the list of available wallets:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
const wallets = dAppKit.stores.$wallets.get();
|
|
122
|
+
|
|
123
|
+
wallets.forEach((wallet) => {
|
|
124
|
+
console.log('Wallet:', wallet.name);
|
|
125
|
+
console.log('Icon:', wallet.icon);
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Subscribing to State Changes
|
|
130
|
+
|
|
131
|
+
You can subscribe directly to stores:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// Subscribe to connection changes
|
|
135
|
+
dAppKit.stores.$connection.subscribe((connection) => {
|
|
136
|
+
const statusElement = document.getElementById('connection-status');
|
|
137
|
+
if (statusElement === null) return;
|
|
138
|
+
if (connection.isConnected && connection.account) {
|
|
139
|
+
statusElement.textContent = `Connected: ${connection.account.address}`;
|
|
140
|
+
} else {
|
|
141
|
+
statusElement.textContent = 'Not connected';
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Subscribe to network changes
|
|
146
|
+
dAppKit.stores.$currentNetwork.subscribe((network) => {
|
|
147
|
+
const networkElement = document.getElementById('current-network');
|
|
148
|
+
if (networkElement === null) return;
|
|
149
|
+
networkElement.textContent = `Network: ${network}`;
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## React
|
|
154
|
+
|
|
155
|
+
React users can use the [provided hooks](./react/hooks/use-wallet-connection) instead of direct
|
|
156
|
+
store access.
|
|
157
|
+
|
|
158
|
+
## Properties
|
|
159
|
+
|
|
160
|
+
Besides stores, some values are available as direct properties:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Get available networks (not a store, just a property)
|
|
164
|
+
const networks = dAppKit.networks; // ['mainnet', 'testnet', ...]
|
|
165
|
+
|
|
166
|
+
// Get client for specific network
|
|
167
|
+
const mainnetClient = dAppKit.getClient('mainnet');
|
|
168
|
+
const currentClient = dAppKit.getClient(); // Current network's client
|
|
169
|
+
```
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Theming
|
|
2
|
+
|
|
3
|
+
> Customize the appearance of dApp Kit UI components
|
|
4
|
+
|
|
5
|
+
The dApp Kit web components use a theming system compatible with
|
|
6
|
+
[shadcn/ui](https://ui.shadcn.com/docs/theming). Components are customized using CSS custom
|
|
7
|
+
properties (CSS variables), allowing you to match them to your application's design system.
|
|
8
|
+
|
|
9
|
+
> **Note:** **shadcn/ui Compatibility**: The dApp Kit uses the same CSS custom property naming convention as
|
|
10
|
+
> shadcn/ui. If your application already uses shadcn/ui themes, the dApp Kit components will
|
|
11
|
+
> automatically inherit your theme. You can also use [shadcn/ui's theme
|
|
12
|
+
> builder](https://ui.shadcn.com/themes) to create custom themes.
|
|
13
|
+
|
|
14
|
+
## CSS Custom Properties
|
|
15
|
+
|
|
16
|
+
All dApp Kit web components support the following CSS custom properties:
|
|
17
|
+
|
|
18
|
+
### Colors
|
|
19
|
+
|
|
20
|
+
These color variables follow the shadcn/ui naming convention. Colors can be defined using any valid
|
|
21
|
+
CSS color format (hex, rgb, hsl, oklch, etc.).
|
|
22
|
+
|
|
23
|
+
- **`--background`** - Background color of the component. Used as the default background for UI
|
|
24
|
+
elements.
|
|
25
|
+
- **`--foreground`** - Foreground color of the component. Used as the default text color.
|
|
26
|
+
- **`--primary`** - Primary color used for interactive elements such as buttons and links.
|
|
27
|
+
- **`--primary-foreground`** - Text or icon color placed on top of primary elements.
|
|
28
|
+
- **`--secondary`** - Secondary color used for less prominent interactive elements.
|
|
29
|
+
- **`--secondary-foreground`** - Text or icon color placed on top of secondary elements.
|
|
30
|
+
- **`--border`** - Border color for UI elements.
|
|
31
|
+
- **`--accent`** - Accent color used for highlights and decorative elements.
|
|
32
|
+
- **`--accent-foreground`** - Text or icon color placed on top of accent elements.
|
|
33
|
+
- **`--muted`** - Background color for subtle or muted UI elements (e.g., placeholders, disabled
|
|
34
|
+
states).
|
|
35
|
+
- **`--muted-foreground`** - Text or icon color for muted UI elements.
|
|
36
|
+
- **`--popover`** - Background color for floating elements such as popovers, dropdowns, or tooltips.
|
|
37
|
+
- **`--popover-foreground`** - Text or icon color inside popover elements.
|
|
38
|
+
- **`--ring`** - Color used for focus rings (visible focus indicators on interactive elements).
|
|
39
|
+
|
|
40
|
+
### Typography
|
|
41
|
+
|
|
42
|
+
- **`--font-sans`** - Font family used for text content.
|
|
43
|
+
- **`--font-weight-medium`** - Medium font weight for text (typically used for buttons and
|
|
44
|
+
interactive elements).
|
|
45
|
+
- **`--font-weight-semibold`** - Semibold font weight for text (typically used for headings or
|
|
46
|
+
emphasized text).
|
|
47
|
+
|
|
48
|
+
### Layout
|
|
49
|
+
|
|
50
|
+
- **`--radius`** - Border radius used for UI elements.
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Global Theming
|
|
55
|
+
|
|
56
|
+
Apply custom properties to affect all dApp Kit components:
|
|
57
|
+
|
|
58
|
+
```css
|
|
59
|
+
:root {
|
|
60
|
+
--primary: #4f46e5;
|
|
61
|
+
--primary-foreground: #ffffff;
|
|
62
|
+
--background: #ffffff;
|
|
63
|
+
--foreground: #0f172a;
|
|
64
|
+
--border: #e2e8f0;
|
|
65
|
+
--radius: 0.5rem;
|
|
66
|
+
--font-sans: 'Inter', sans-serif;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Component-Specific Theming
|
|
71
|
+
|
|
72
|
+
Target specific components:
|
|
73
|
+
|
|
74
|
+
```css
|
|
75
|
+
mysten-dapp-kit-connect-button {
|
|
76
|
+
--primary: #10b981;
|
|
77
|
+
--primary-foreground: #ffffff;
|
|
78
|
+
--radius: 0.75rem;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mysten-dapp-kit-connect-modal {
|
|
82
|
+
--background: #f8fafc;
|
|
83
|
+
--popover: #ffffff;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Dark Mode
|
|
88
|
+
|
|
89
|
+
Implement dark mode by overriding the custom properties:
|
|
90
|
+
|
|
91
|
+
```css
|
|
92
|
+
:root {
|
|
93
|
+
--background: #ffffff;
|
|
94
|
+
--foreground: #0f172a;
|
|
95
|
+
--primary: #4f46e5;
|
|
96
|
+
--border: #e2e8f0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@media (prefers-color-scheme: dark) {
|
|
100
|
+
:root {
|
|
101
|
+
--background: #0f172a;
|
|
102
|
+
--foreground: #f1f5f9;
|
|
103
|
+
--primary: #818cf8;
|
|
104
|
+
--border: #334155;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Or use a class-based approach:
|
|
110
|
+
|
|
111
|
+
```css
|
|
112
|
+
.light-theme {
|
|
113
|
+
--background: #ffffff;
|
|
114
|
+
--foreground: #0f172a;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.dark-theme {
|
|
118
|
+
--background: #0f172a;
|
|
119
|
+
--foreground: #f1f5f9;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<div className={isDark ? 'dark-theme' : 'light-theme'}>
|
|
125
|
+
<ConnectButton />
|
|
126
|
+
</div>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Example: Complete Theme
|
|
130
|
+
|
|
131
|
+
Here's a complete theme example matching a custom design system:
|
|
132
|
+
|
|
133
|
+
```css
|
|
134
|
+
:root {
|
|
135
|
+
/* Colors */
|
|
136
|
+
--background: hsl(0 0% 100%);
|
|
137
|
+
--foreground: hsl(222.2 84% 4.9%);
|
|
138
|
+
--primary: hsl(221.2 83.2% 53.3%);
|
|
139
|
+
--primary-foreground: hsl(210 40% 98%);
|
|
140
|
+
--secondary: hsl(210 40% 96.1%);
|
|
141
|
+
--secondary-foreground: hsl(222.2 47.4% 11.2%);
|
|
142
|
+
--accent: hsl(210 40% 96.1%);
|
|
143
|
+
--accent-foreground: hsl(222.2 47.4% 11.2%);
|
|
144
|
+
--muted: hsl(210 40% 96.1%);
|
|
145
|
+
--muted-foreground: hsl(215.4 16.3% 46.9%);
|
|
146
|
+
--border: hsl(214.3 31.8% 91.4%);
|
|
147
|
+
--popover: hsl(0 0% 100%);
|
|
148
|
+
--popover-foreground: hsl(222.2 84% 4.9%);
|
|
149
|
+
--ring: hsl(221.2 83.2% 53.3%);
|
|
150
|
+
|
|
151
|
+
/* Typography */
|
|
152
|
+
--font-sans:
|
|
153
|
+
system-ui, -apple-system, 'Segoe UI', 'Roboto', 'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
|
|
154
|
+
--font-weight-medium: 500;
|
|
155
|
+
--font-weight-semibold: 600;
|
|
156
|
+
|
|
157
|
+
/* Layout */
|
|
158
|
+
--radius: 0.5rem;
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Framework Integration
|
|
163
|
+
|
|
164
|
+
### React
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
|
|
168
|
+
return <ConnectButton />;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Vue
|
|
173
|
+
|
|
174
|
+
```vue
|
|
175
|
+
<template>
|
|
176
|
+
<mysten-dapp-kit-connect-button :instance="dAppKit" />
|
|
177
|
+
</template>
|
|
178
|
+
|
|
179
|
+
<style>
|
|
180
|
+
@import './theme.css';
|
|
181
|
+
</style>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Vanilla JavaScript
|
|
185
|
+
|
|
186
|
+
```html
|
|
187
|
+
<!doctype html>
|
|
188
|
+
<html>
|
|
189
|
+
<head>
|
|
190
|
+
<link rel="stylesheet" href="theme.css" />
|
|
191
|
+
</head>
|
|
192
|
+
<body>
|
|
193
|
+
<mysten-dapp-kit-connect-button></mysten-dapp-kit-connect-button>
|
|
194
|
+
</body>
|
|
195
|
+
</html>
|
|
196
|
+
```
|