@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.
Files changed (35) hide show
  1. package/dist/index.d.mts +1 -2
  2. package/dist/index.d.mts.map +1 -1
  3. package/dist/ui.d.mts +3 -3
  4. package/dist/ui.d.mts.map +1 -1
  5. package/docs/actions/connect-wallet.md +69 -0
  6. package/docs/actions/disconnect-wallet.md +39 -0
  7. package/docs/actions/sign-and-execute-transaction.md +96 -0
  8. package/docs/actions/sign-personal-message.md +58 -0
  9. package/docs/actions/sign-transaction.md +65 -0
  10. package/docs/actions/switch-account.md +37 -0
  11. package/docs/actions/switch-network.md +37 -0
  12. package/docs/dapp-kit-instance.md +163 -0
  13. package/docs/getting-started/create-dapp.md +151 -0
  14. package/docs/getting-started/next-js.md +163 -0
  15. package/docs/getting-started/react.md +172 -0
  16. package/docs/getting-started/vue.md +193 -0
  17. package/docs/index.md +70 -0
  18. package/docs/llms-index.md +33 -0
  19. package/docs/react/components/connect-button.md +42 -0
  20. package/docs/react/components/connect-modal.md +51 -0
  21. package/docs/react/components/index.md +13 -0
  22. package/docs/react/dapp-kit-provider.md +86 -0
  23. package/docs/react/hooks/index.md +26 -0
  24. package/docs/react/hooks/use-current-account.md +33 -0
  25. package/docs/react/hooks/use-current-client.md +36 -0
  26. package/docs/react/hooks/use-current-network.md +28 -0
  27. package/docs/react/hooks/use-current-wallet.md +36 -0
  28. package/docs/react/hooks/use-dapp-kit.md +100 -0
  29. package/docs/react/hooks/use-wallet-connection.md +48 -0
  30. package/docs/react/hooks/use-wallets.md +33 -0
  31. package/docs/state.md +169 -0
  32. package/docs/theming.md +196 -0
  33. package/docs/web-components/connect-button.md +89 -0
  34. package/docs/web-components/connect-modal.md +177 -0
  35. package/package.json +5 -5
package/dist/index.d.mts CHANGED
@@ -2,7 +2,6 @@ import * as _mysten_dapp_kit_core5 from "@mysten/dapp-kit-core";
2
2
  import { DAppKit, DefaultExpectedDppKit, RegisteredDAppKit } from "@mysten/dapp-kit-core";
3
3
  import * as react0 from "react";
4
4
  import { PropsWithChildren } from "react";
5
- import * as react_jsx_runtime1 from "react/jsx-runtime";
6
5
  import * as nanostores0 from "nanostores";
7
6
  export * from "@mysten/dapp-kit-core";
8
7
 
@@ -14,7 +13,7 @@ type DAppKitProviderProps = PropsWithChildren<{
14
13
  declare function DAppKitProvider({
15
14
  dAppKit,
16
15
  children
17
- }: DAppKitProviderProps): react_jsx_runtime1.JSX.Element;
16
+ }: DAppKitProviderProps): react0.JSX.Element;
18
17
  //#endregion
19
18
  //#region src/hooks/useDAppKit.d.ts
20
19
  declare function useDAppKit<TDAppKit extends DAppKit<any> = RegisteredDAppKit>(dAppKit?: TDAppKit): TDAppKit;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/components/DAppKitProvider.tsx","../src/hooks/useDAppKit.ts","../src/hooks/useWallets.ts","../src/hooks/useWalletConnection.ts","../src/hooks/useCurrentAccount.ts","../src/hooks/useCurrentWallet.ts","../src/hooks/useCurrentClient.ts","../src/hooks/useCurrentNetwork.ts"],"mappings":";;;;;;;;;cAOa,cAAA,EAAc,MAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,OAAA,MAAoD,sBAAA,CAApD,iBAAA;AAAA,KAEf,oBAAA,GAAuB,iBAAA;EAClC,OAAA,EAAS,qBAAA;AAAA;AAAA,iBAGM,eAAA,CAAA;EAAkB,OAAA;EAAS;AAAA,GAAY,oBAAA,GAAoB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;iBCN3D,UAAA,kBAA4B,OAAA,QAAe,iBAAA,CAAA,CAAmB,OAAA,GAAU,QAAA,GAAQ,QAAA;;;KCApF,iBAAA,kBAAmC,OAAA;EAC9C,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,UAAA,kBAA4B,OAAA,QAAe,iBAAA,CAAA,CAAA;EAC1D;AAAA,IACE,iBAAA,CAAkB,QAAA,IAAD,sBAAA,CAAe,QAAA;;;KCNvB,0BAAA,kBAA4C,OAAA;EACvD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,mBAAA,kBAAqC,OAAA,GAAU,iBAAA,CAAA,CAAA;EAC9D;AAAA,IACE,0BAAA,CAA2B,QAAA;EAAA;;;;;;;;;mBAAD,sBAAA,CAAA,QAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCPjB,wBAAA,kBAA0C,OAAA;EACrD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,iBAAA,kBAAmC,OAAA,QAAe,iBAAA,CAAA,CAAA;EACjE;AAAA,IACE,wBAAA,CAAyB,QAAA,IAAD,sBAAA,CAAe,eAAA;;;KCN9B,uBAAA,kBAAyC,OAAA;EACpD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,gBAAA,kBAAkC,OAAA,QAAe,iBAAA,CAAA,CAAA;EAChE;AAAA,IACE,uBAAA,CAAwB,QAAA,IAAD,sBAAA,CAAe,QAAA;;;KCL7B,uBAAA,kBAAyC,OAAA;EACpD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,gBAAA,kBAAkC,OAAA,QAAe,iBAAA,CAAA,CAAA;EAChE;AAAA,IACE,uBAAA,CAAwB,QAAA,IAEyB,UAAA,CAAW,QAAA;;;KCRnD,wBAAA,kBAA0C,OAAA;EACrD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,iBAAA,kBAAmC,OAAA,QAAe,iBAAA,CAAA,CAAA;EACjE;AAAA,IACE,wBAAA,CAAyB,QAAA,IAAc,WAAA,CAAA,UAAA,CAAA,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/components/DAppKitProvider.tsx","../src/hooks/useDAppKit.ts","../src/hooks/useWallets.ts","../src/hooks/useWalletConnection.ts","../src/hooks/useCurrentAccount.ts","../src/hooks/useCurrentWallet.ts","../src/hooks/useCurrentClient.ts","../src/hooks/useCurrentNetwork.ts"],"mappings":";;;;;;;;cAOa,cAAA,EAAc,MAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,OAAA,MAAoD,sBAAA,CAApD,iBAAA;AAAA,KAEf,oBAAA,GAAuB,iBAAA;EAClC,OAAA,EAAS,qBAAA;AAAA;AAAA,iBAGM,eAAA,CAAA;EAAkB,OAAA;EAAS;AAAA,GAAY,oBAAA,GAAoB,MAAA,CAAA,GAAA,CAAA,OAAA;;;iBCN3D,UAAA,kBAA4B,OAAA,QAAe,iBAAA,CAAA,CAAmB,OAAA,GAAU,QAAA,GAAQ,QAAA;;;KCApF,iBAAA,kBAAmC,OAAA;EAC9C,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,UAAA,kBAA4B,OAAA,QAAe,iBAAA,CAAA,CAAA;EAC1D;AAAA,IACE,iBAAA,CAAkB,QAAA,IAAD,sBAAA,CAAe,QAAA;;;KCNvB,0BAAA,kBAA4C,OAAA;EACvD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,mBAAA,kBAAqC,OAAA,GAAU,iBAAA,CAAA,CAAA;EAC9D;AAAA,IACE,0BAAA,CAA2B,QAAA;EAAA;;;;;;;;;mBAAD,sBAAA,CAAA,QAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCPjB,wBAAA,kBAA0C,OAAA;EACrD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,iBAAA,kBAAmC,OAAA,QAAe,iBAAA,CAAA,CAAA;EACjE;AAAA,IACE,wBAAA,CAAyB,QAAA,IAAD,sBAAA,CAAe,eAAA;;;KCN9B,uBAAA,kBAAyC,OAAA;EACpD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,gBAAA,kBAAkC,OAAA,QAAe,iBAAA,CAAA,CAAA;EAChE;AAAA,IACE,uBAAA,CAAwB,QAAA,IAAD,sBAAA,CAAe,QAAA;;;KCL7B,uBAAA,kBAAyC,OAAA;EACpD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,gBAAA,kBAAkC,OAAA,QAAe,iBAAA,CAAA,CAAA;EAChE;AAAA,IACE,uBAAA,CAAwB,QAAA,IAEyB,UAAA,CAAW,QAAA;;;KCRnD,wBAAA,kBAA0C,OAAA;EACrD,OAAA,GAAU,QAAA;AAAA;AAAA,iBAGK,iBAAA,kBAAmC,OAAA,QAAe,iBAAA,CAAA,CAAA;EACjE;AAAA,IACE,wBAAA,CAAyB,QAAA,IAAc,WAAA,CAAA,UAAA,CAAA,QAAA"}
package/dist/ui.d.mts CHANGED
@@ -1,5 +1,5 @@
1
+ import * as React from "react";
1
2
  import { ComponentProps } from "react";
2
- import * as react_jsx_runtime0 from "react/jsx-runtime";
3
3
  import * as _lit_react0 from "@lit/react";
4
4
  import { DAppKitConnectButton, DAppKitConnectModal } from "@mysten/dapp-kit-core/web";
5
5
 
@@ -9,7 +9,7 @@ declare const ConnectButtonComponent: _lit_react0.ReactWebComponent<DAppKitConne
9
9
  declare function ConnectButton({
10
10
  instance,
11
11
  ...props
12
- }: ConnectButtonProps): react_jsx_runtime0.JSX.Element;
12
+ }: ConnectButtonProps): React.JSX.Element;
13
13
  //#endregion
14
14
  //#region src/components/ConnectModal.d.ts
15
15
  type ConnectModalProps = ComponentProps<typeof ConnectModalComponent>;
@@ -17,7 +17,7 @@ declare const ConnectModalComponent: _lit_react0.ReactWebComponent<DAppKitConnec
17
17
  declare function ConnectModal({
18
18
  instance,
19
19
  ...props
20
- }: ConnectModalProps): react_jsx_runtime0.JSX.Element;
20
+ }: ConnectModalProps): React.JSX.Element;
21
21
  //#endregion
22
22
  export { ConnectButton, type ConnectButtonProps, ConnectModal, type ConnectModalProps };
23
23
  //# sourceMappingURL=ui.d.mts.map
package/dist/ui.d.mts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.d.mts","names":[],"sources":["../src/components/ConnectButton.tsx","../src/components/ConnectModal.tsx"],"mappings":";;;;;;KASY,kBAAA,GAAqB,cAAA,QAAsB,sBAAA;AAAA,cAEjD,sBAAA,EAAsB,WAAA,CAAA,iBAAA,CAAA,oBAAA;AAAA,iBAMZ,aAAA,CAAA;EAAgB,QAAA;EAAA,GAAa;AAAA,GAAS,kBAAA,GAAkB,kBAAA,CAAA,GAAA,CAAA,OAAA;;;KCR5D,iBAAA,GAAoB,cAAA,QAAsB,qBAAA;AAAA,cAEhD,qBAAA,EAAqB,WAAA,CAAA,iBAAA,CAAA,mBAAA;AAAA,iBAMX,YAAA,CAAA;EAAe,QAAA;EAAA,GAAa;AAAA,GAAS,iBAAA,GAAiB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"ui.d.mts","names":[],"sources":["../src/components/ConnectButton.tsx","../src/components/ConnectModal.tsx"],"mappings":";;;;;;KASY,kBAAA,GAAqB,cAAA,QAAsB,sBAAA;AAAA,cAEjD,sBAAA,EAAsB,WAAA,CAAA,iBAAA,CAAA,oBAAA;AAAA,iBAMZ,aAAA,CAAA;EAAgB,QAAA;EAAA,GAAa;AAAA,GAAS,kBAAA,GAAkB,KAAA,CAAA,GAAA,CAAA,OAAA;;;KCR5D,iBAAA,GAAoB,cAAA,QAAsB,qBAAA;AAAA,cAEhD,qBAAA,EAAqB,WAAA,CAAA,iBAAA,CAAA,mBAAA;AAAA,iBAMX,YAAA,CAAA;EAAe,QAAA;EAAA,GAAa;AAAA,GAAS,iBAAA,GAAiB,KAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -0,0 +1,69 @@
1
+ # Connect Wallet
2
+
3
+ > Programmatically connect to a Sui wallet using the dApp Kit connectWallet action.
4
+
5
+ The dApp Kit SDK provides an action for wallet connection, allowing users to connect, disconnect,
6
+ and switch between wallets and accounts.
7
+
8
+ > The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
9
+ > connection UI.
10
+
11
+ ## Usage
12
+
13
+ > Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
14
+ > page reload. This provides a seamless user experience but can be
15
+ > [disabled](../dapp-kit-instance#disabling-auto-connect) if needed.
16
+
17
+ The `connectWallet` action prompts a wallet to connect and authorize accounts for your application:
18
+
19
+ ```typescript
20
+
21
+ const dAppKit = createDAppKit({
22
+ /* config */
23
+ });
24
+
25
+ // Connect to a specific wallet
26
+ const result = await dAppKit.connectWallet({
27
+ wallet: myWallet, // UiWallet instance
28
+ account: myAccount, // Optional: specific account to select
29
+ });
30
+
31
+ console.log('Connected accounts:', result.accounts);
32
+ ```
33
+
34
+ ## Parameters
35
+
36
+ - **`wallet`:** The `UiWallet` instance to connect to
37
+ - **`account`** (optional) - A specific `UiWalletAccount` to set as the selected account. Defaults
38
+ to the first authorized account
39
+
40
+ ## Return value
41
+
42
+ Returns a `Promise` that resolves to an object containing:
43
+
44
+ - **`accounts`:** Array of authorized `UiWalletAccount` instances
45
+
46
+ ## Example
47
+
48
+ ```typescript
49
+ const wallets = dAppKit.stores.$wallets.get();
50
+
51
+ const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
52
+ if (connection.isConnected) {
53
+ console.log(`Connected account address: ${connection.account.address}`);
54
+ } else {
55
+ console.log({ connection });
56
+ }
57
+ });
58
+
59
+ if (wallets.length > 0) {
60
+ try {
61
+ const { accounts } = await dAppKit.connectWallet({
62
+ wallet: wallets[0],
63
+ });
64
+ console.log('Available accounts:', accounts);
65
+ } catch (error) {
66
+ console.error('Connection failed:', error);
67
+ }
68
+ }
69
+ ```
@@ -0,0 +1,39 @@
1
+ # Disconnect Wallet
2
+
3
+ > Programmatically disconnect from a Sui wallet using the dApp Kit disconnectWallet action.
4
+
5
+ The `disconnectWallet` action terminates the connection with the currently connected wallet.
6
+
7
+ > The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
8
+ > connection UI.
9
+
10
+ ## Usage
11
+
12
+ > **Note:** The disconnect action clears the connection state locally and attempts to notify the wallet. Even
13
+ > if the wallet notification fails, the local state is always cleared to ensure a clean
14
+ > disconnection.
15
+ >
16
+ > Wallets might or might not implement the `disconnect` feature. Calling `disconnectWallet`
17
+ > does not necessarily mean that the wallet accounts are disconnected from the app within the
18
+ > wallet itself. This is determined by each wallet's implementation.
19
+
20
+ ```typescript
21
+
22
+ const dAppKit = createDAppKit({
23
+ /* config */
24
+ });
25
+
26
+ await dAppKit.disconnectWallet();
27
+ ```
28
+
29
+ ## Parameters
30
+
31
+ None.
32
+
33
+ ## Return value
34
+
35
+ Returns a `Promise` that resolves to `void` when the disconnection is complete.
36
+
37
+ > The action might throw `WalletNotConnectedError` if no wallet is connected. However,
38
+ > wallet-specific disconnect failures are logged but don't prevent the local connection state from
39
+ > being cleared.
@@ -0,0 +1,96 @@
1
+ # Sign and Execute Transaction
2
+
3
+ > Sign and execute a transaction on the Sui network using the connected wallet.
4
+
5
+ The `signAndExecuteTransaction` action prompts the connected wallet to sign and immediately execute
6
+ a transaction on the Sui network. This is the most common way to execute transactions in your app.
7
+
8
+ ## Usage
9
+
10
+ ```typescript
11
+
12
+ const dAppKit = createDAppKit({
13
+ /* config */
14
+ });
15
+
16
+ const tx = new Transaction();
17
+ // No need to manually set sender - it's done automatically
18
+ tx.transferObjects([coinWithBalance({ balance: 123 })], '0xrecipient...');
19
+
20
+ const result = await dAppKit.signAndExecuteTransaction({
21
+ transaction: tx,
22
+ });
23
+
24
+ if (result.FailedTransaction) {
25
+ throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
26
+ }
27
+
28
+ console.log('Transaction digest:', result.Transaction.digest);
29
+ ```
30
+
31
+ ## Parameters
32
+
33
+ - **`transaction`:** `Transaction | string`: The transaction to sign and execute. Can be either a
34
+ Transaction instance or base64-encoded bcs bytes for the transaction.
35
+ - **`signal`** (optional): `AbortSignal`: An abort signal to cancel the transaction request.
36
+
37
+ ## Return value
38
+
39
+ Returns a `Promise` that resolves to a `TransactionResult` discriminated union:
40
+
41
+ ```typescript
42
+ type TransactionResult =
43
+ | { $kind: 'Transaction'; Transaction: Transaction }
44
+ | { $kind: 'FailedTransaction'; FailedTransaction: Transaction };
45
+ ```
46
+
47
+ The `Transaction` object contains:
48
+
49
+ - **`digest`:** `string`: The transaction digest (unique identifier for the executed transaction)
50
+ - **`signatures`:** `string[]`: The signatures as base64-encoded strings
51
+ - **`epoch`:** `string | null`: The epoch in which the transaction was executed
52
+ - **`status`:** `ExecutionStatus`: The execution status with `success: boolean` and
53
+ `error: string | null`
54
+ - **`effects`:** `TransactionEffects | null`: The parsed transaction effects (may be `null` if
55
+ effects parsing fails for unknown effect versions)
56
+ - **`transaction`:** `TransactionData`: The parsed transaction data
57
+
58
+ ```typescript
59
+ const result = await dAppKit.signAndExecuteTransaction({ transaction });
60
+
61
+ if (result.FailedTransaction) {
62
+ console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
63
+ return;
64
+ }
65
+
66
+ // Access the successful transaction results
67
+ const tx = result.Transaction;
68
+ console.log('Digest:', tx.digest);
69
+ console.log('Signatures:', tx.signatures);
70
+ console.log('Epoch:', tx.epoch);
71
+ ```
72
+
73
+ ## Transaction building
74
+
75
+ When passing a Transaction instance, the action automatically:
76
+
77
+ 1. Sets the sender address if not already set
78
+ 2. Builds the transaction using the current network's client
79
+ 3. Converts it to the appropriate format for the wallet
80
+ 4. Submits the transaction to the network
81
+
82
+ ## Wallet compatibility
83
+
84
+ - The action transparently handles both `sui:signAndExecuteTransaction` and
85
+ `sui:signAndExecuteTransactionBlock` wallet-standard features
86
+ - The wallet handles network submission and response
87
+ - Some wallets (Enoki, Enoki Connect, and WalletConnect) might use the dApp Kit client and execute
88
+ transactions within the application as an implementation detail
89
+
90
+ ```typescript
91
+ // The action automatically detects and uses the appropriate method
92
+ // No special configuration needed
93
+ const result = await dAppKit.signAndExecuteTransaction({
94
+ transaction: tx,
95
+ });
96
+ ```
@@ -0,0 +1,58 @@
1
+ # Sign Personal Message
2
+
3
+ > Sign an arbitrary message with the connected wallet for authentication or proof of ownership.
4
+
5
+ The `signPersonalMessage` action prompts the connected wallet to sign a personal message. This is
6
+ useful for authentication, proof of ownership, or other scenarios where you need cryptographic proof
7
+ that a user controls a specific account.
8
+
9
+ ## Usage
10
+
11
+ ```typescript
12
+
13
+ const dAppKit = createDAppKit({
14
+ /* config */
15
+ });
16
+
17
+ const message = new TextEncoder().encode('Please sign this message');
18
+ const result = await dAppKit.signPersonalMessage({
19
+ message,
20
+ });
21
+
22
+ console.log('Message bytes:', result.bytes);
23
+ console.log('Signature:', result.signature);
24
+ ```
25
+
26
+ ## Parameters
27
+
28
+ - **`message`:** `Uint8Array` - The message to sign as a byte array
29
+
30
+ ## Return value
31
+
32
+ Returns a `Promise` that resolves to an object containing:
33
+
34
+ - **`bytes`:** `string` - Base64 encoded message bytes
35
+ - **`signature`:** `string` - Base64 encoded signature
36
+
37
+ ## Message format
38
+
39
+ The message parameter must be a `Uint8Array`. Common patterns for creating byte arrays:
40
+
41
+ ```typescript
42
+ const textMessage = new TextEncoder().encode('Hello, Sui!');
43
+ await dAppKit.signPersonalMessage({ message: textMessage });
44
+
45
+ const jsonMessage = new TextEncoder().encode(
46
+ JSON.stringify({ action: 'sign', timestamp: Date.now() }),
47
+ );
48
+ await dAppKit.signPersonalMessage({ message: jsonMessage });
49
+ ```
50
+
51
+ ## Security considerations
52
+
53
+ ### Message content
54
+
55
+ - Always display the message content clearly to users before signing
56
+ - Avoid signing opaque or encoded data that users cannot understand
57
+ - Include human-readable prefixes for different message types
58
+ - Consider adding timestamps to prevent replay attacks
@@ -0,0 +1,65 @@
1
+ # Sign Transaction
2
+
3
+ > Sign a Sui transaction without executing it for deferred or multi-signature scenarios.
4
+
5
+ The `signTransaction` action prompts the connected wallet to sign a transaction without executing
6
+ it. This is useful when you need a signed transaction for later execution or for multi-signature
7
+ scenarios.
8
+
9
+ ## Usage
10
+
11
+ ```typescript
12
+
13
+ const dAppKit = createDAppKit({
14
+ /* config */
15
+ });
16
+
17
+ const tx = new Transaction();
18
+ // No need to manually set sender - it's done automatically
19
+ tx.transferObjects([coinWithBalance({ balance: 123 })], '0xrecipient...');
20
+
21
+ // Sign the transaction without executing it
22
+ const { bytes, signature } = await dAppKit.signTransaction({
23
+ transaction: tx,
24
+ });
25
+ ```
26
+
27
+ ## Parameters
28
+
29
+ - **`transaction`:** `Transaction | string` - The transaction to sign. Can be either a Transaction
30
+ instance or base64-encoded bcs bytes for the transaction.
31
+ - **`signal`** (optional) - `AbortSignal` - An abort signal to cancel the signing request.
32
+
33
+ ## Return value
34
+
35
+ Returns a `Promise` that resolves to an object containing:
36
+
37
+ - **`bytes`:** `string` - The signed transaction as a base64-encoded BCS string
38
+ - **`signature`:** `string` - The signature as a base64-encoded string
39
+
40
+ ```typescript
41
+ const result = await dAppKit.signTransaction({ transaction });
42
+ console.log('Signed transaction bytes:', result.bytes);
43
+ console.log('Signature:', result.signature);
44
+ ```
45
+
46
+ ## Transaction building
47
+
48
+ When passing a Transaction instance, the action automatically:
49
+
50
+ 1. Sets the sender address if not already set
51
+ 2. Builds the transaction using the current network's client
52
+ 3. Converts it to the appropriate format for the wallet
53
+
54
+ ## Wallet compatibility
55
+
56
+ - The action transparently handles both `sui:signTransaction` and `sui:signTransactionBlock`
57
+ wallet-standard features
58
+
59
+ ```typescript
60
+ // The action automatically detects and uses the appropriate method
61
+ // No special configuration needed
62
+ const result = await dAppKit.signTransaction({
63
+ transaction: tx,
64
+ });
65
+ ```
@@ -0,0 +1,37 @@
1
+ # Switch Account
2
+
3
+ > Switch the active account in the connected wallet using the dApp Kit switchAccount action.
4
+
5
+ The `switchAccount` action changes the currently selected account to a different account from the
6
+ connected wallet.
7
+
8
+ > **Note:** The current account is a dApp Kit concept that tracks which account is active within your
9
+ > application. Changing the active account in the app does not affect the wallet itself, and wallets
10
+ > are not notified when the active account changes.
11
+
12
+ > Account switching is integrated into the [Connect Button](../web-components/connect-button) Web
13
+ > Component. When a wallet is connected with multiple accounts, the button provides an account
14
+ > selector.
15
+
16
+ ## Usage
17
+
18
+ ```typescript
19
+
20
+ const dAppKit = createDAppKit({
21
+ /* config */
22
+ });
23
+
24
+ // Switch to a different account
25
+ dAppKit.switchAccount({
26
+ account: anotherAccount, // UiWalletAccount from the connected wallet
27
+ });
28
+ ```
29
+
30
+ ## Parameters
31
+
32
+ - **`account`:** `UiWalletAccount` - The account to switch to. Must be an account that belongs to
33
+ the currently connected wallet.
34
+
35
+ ## Return value
36
+
37
+ Returns `void`. The action completes synchronously and updates the connection state immediately.
@@ -0,0 +1,37 @@
1
+ # Switch Network
2
+
3
+ > Switch the active network for the dApp Kit instance between mainnet, testnet, and other networks.
4
+
5
+ The `switchNetwork` action changes the currently selected network that the dApp Kit client is
6
+ configured to use.
7
+
8
+ > **Note:** Network switching only affects your app's client connection. The wallet itself is not affected by
9
+ > this change, and wallets are not notified when the network changes in the app.
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+
15
+ const GRPC_URLS = {
16
+ mainnet: 'https://fullnode.mainnet.sui.io:443',
17
+ testnet: 'https://fullnode.testnet.sui.io:443',
18
+ } as const;
19
+
20
+ const dAppKit = createDAppKit({
21
+ networks: ['mainnet', 'testnet'],
22
+ defaultNetwork: 'mainnet',
23
+ createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
24
+ });
25
+
26
+ // Switch to a different network
27
+ dAppKit.switchNetwork('testnet');
28
+ ```
29
+
30
+ ## Parameters
31
+
32
+ - **`network`:** `TNetworks[number]`: The network to switch to. Must be one of the networks
33
+ configured when creating the dApp Kit instance.
34
+
35
+ ## Return value
36
+
37
+ Returns `void`. The action completes synchronously and updates the network state immediately.
@@ -0,0 +1,163 @@
1
+ # DApp Kit Instance
2
+
3
+ > Create and configure a DAppKit instance for wallet and client management
4
+
5
+ The `createDAppKit` function is the foundation of your Sui app. It creates an instance that manages
6
+ wallet connections, network configuration, and provides access to the Sui client.
7
+
8
+ ## Creating a dApp Kit instance
9
+
10
+ The core of the dApp Kit SDK is the `createDAppKit` function, which creates an instance that manages
11
+ all app functionality:
12
+
13
+ ```typescript
14
+
15
+ const GRPC_URLS = {
16
+ testnet: 'https://fullnode.testnet.sui.io:443',
17
+ };
18
+
19
+ networks: ['testnet'],
20
+ createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
21
+ });
22
+ ```
23
+
24
+ > **Note:** If you use the React bindings, there are two ways to ensure type safety with hooks:
25
+ >
26
+ > 1. [Register the global dAppKit type](./getting-started/react#step-1-create-a-dapp-kit-instance) once, and all hooks will be properly typed
27
+ > 2. Pass the dAppKit instance explicitly to each hook: `useWalletConnection({ dAppKit })`
28
+
29
+ This instance provides:
30
+
31
+ - Wallet connection management
32
+ - Network switching capabilities
33
+ - Client access for blockchain interactions
34
+ - State stores for reactive updates
35
+
36
+ ## Parameters
37
+
38
+ - **autoConnect** (optional): Enables automatically connecting to the most recently used wallet
39
+ account (default: `true`)
40
+ - **networks:** A list of networks supported by the application (for example,
41
+ `['mainnet', 'testnet']`)
42
+ - **defaultNetwork** (optional): Initial network to use (default: first network in the array)
43
+ - **createClient:** Creates a new client instance for the given network
44
+ - **enableBurnerWallet** (optional): Enable development-only burner wallet (default: `false`)
45
+ - **storage** (optional): Configures how the most recently connected to wallet account is stored
46
+ (default: `localStorage`, set to `null` to disable)
47
+ - **storageKey** (optional): The key to use to store the most recently connected wallet account
48
+ (default: `'mysten-dapp-kit:selected-wallet-and-address'`)
49
+ - **walletInitializers** (optional): A list of wallet initializers used for registering additional
50
+ wallet standard wallets.
51
+ - **slushWalletConfig** (optional): Configuration for Slush wallet (set to `null` to disable the
52
+ wallet)
53
+
54
+ ## Return value
55
+
56
+ ```ts
57
+ {
58
+ // Actions
59
+ connectWallet: (args: { wallet: UiWallet; account?: UiWalletAccount }) => Promise<{ accounts: UiWalletAccount[]; }>;
60
+ disconnectWallet: () => Promise<void>;
61
+ switchAccount: (args: { account: UiWalletAccount }) => Promise<void>;
62
+ switchNetwork: (network: string) => void;
63
+ signTransaction: (args: { transaction: Transaction | string; signal?: AbortSignal }) => Promise<SignedTransaction>;
64
+ signAndExecuteTransaction: (args: { transaction: Transaction | string; signal?: AbortSignal }) => Promise<TransactionResult>;
65
+ signPersonalMessage: (args: { message: Uint8Array }) => Promise<SignedPersonalMessage>;
66
+
67
+ // Properties
68
+ networks: string[];
69
+ stores: {
70
+ $wallets: DAppKitStores['$compatibleWallets'];
71
+ $connection: DAppKitStores['$connection'];
72
+ $currentNetwork: ReadableAtom<TNetworks[number]>;
73
+ $currentClient: ReadableAtom<Client>;
74
+ };
75
+ getClient: (network?: string) => Client;
76
+ }
77
+ ```
78
+
79
+ Read more about [actions](./actions/connect-wallet) and [stores](./state).
80
+
81
+ ## Basic usage
82
+
83
+ ```ts
84
+ // dapp-kit.ts
85
+
86
+ const GRPC_URLS = {
87
+ testnet: 'https://fullnode.testnet.sui.io:443',
88
+ };
89
+
90
+ networks: ['testnet'],
91
+ createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
92
+ });
93
+ ```
94
+
95
+ ```ts
96
+ // connect-wallet-and-log.ts
97
+
98
+ wallet,
99
+ account,
100
+ }: {
101
+ wallet: UiWallet;
102
+ account: UiWalletAccount;
103
+ }) {
104
+ const result = await dAppKit.connectWallet({
105
+ wallet,
106
+ account,
107
+ });
108
+ console.log('Connected accounts:', result.accounts);
109
+ }
110
+ ```
111
+
112
+ > If you use the React bindings, see [Getting Started in React](./getting-started/react) and
113
+ > [DAppKitProvider](./react/dapp-kit-provider).
114
+
115
+ ## Development configuration
116
+
117
+ For development environments, enable the burner wallet:
118
+
119
+ ```typescript
120
+
121
+ networks: ['localnet'],
122
+ defaultNetwork: 'localnet',
123
+ createClient: () => new SuiGrpcClient({ network: 'localnet', baseUrl: 'http://127.0.0.1:9000' }),
124
+ enableBurnerWallet: true, // Dev-only feature
125
+ });
126
+ ```
127
+
128
+ ## Auto-connect behavior
129
+
130
+ By default, dApp Kit automatically reconnects to the previously connected wallet.
131
+
132
+ ### Disabling auto-connect
133
+
134
+ ```typescript
135
+
136
+ networks: ['mainnet'],
137
+ createClient: () =>
138
+ new SuiGrpcClient({ network: 'mainnet', baseUrl: 'https://fullnode.mainnet.sui.io:443' }),
139
+ autoConnect: false,
140
+ });
141
+ ```
142
+
143
+ ## Custom wallet integration
144
+
145
+ Add support for custom wallets using wallet initializers:
146
+
147
+ ```typescript
148
+
149
+ networks: ['mainnet'],
150
+ createClient: () =>
151
+ new SuiGrpcClient({ network: 'mainnet', baseUrl: 'https://fullnode.mainnet.sui.io:443' }),
152
+ walletInitializers: [
153
+ {
154
+ id: 'Custom Wallets',
155
+ initialize() {
156
+ const wallets = [new CustomWallet()];
157
+ const walletsApi = getWallets();
158
+ return { unregister: walletsApi.register(...wallets) };
159
+ },
160
+ },
161
+ ],
162
+ });
163
+ ```