@mysten/dapp-kit-core 1.1.4 → 1.2.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/CHANGELOG.md +15 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{types-DCpd4A8C.d.mts → types-CujIIq_S.d.mts} +2 -2
- package/dist/types-CujIIq_S.d.mts.map +1 -0
- package/dist/web/index.d.mts +1 -1
- package/docs/actions/connect-wallet.md +68 -0
- package/docs/actions/disconnect-wallet.md +37 -0
- package/docs/actions/sign-and-execute-transaction.md +95 -0
- package/docs/actions/sign-personal-message.md +57 -0
- package/docs/actions/sign-transaction.md +64 -0
- package/docs/actions/switch-account.md +36 -0
- package/docs/actions/switch-network.md +36 -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 +162 -0
- package/docs/getting-started/react.md +170 -0
- package/docs/getting-started/vue.md +188 -0
- package/docs/index.md +70 -0
- package/docs/llms-index.md +34 -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 +25 -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 +168 -0
- package/docs/theming.md +196 -0
- package/docs/web-components/connect-button.md +87 -0
- package/docs/web-components/connect-modal.md +176 -0
- package/package.json +6 -4
- package/src/index.ts +1 -0
- package/src/wallets/index.ts +2 -2
- package/dist/types-DCpd4A8C.d.mts.map +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Sign and Execute Transaction
|
|
2
|
+
|
|
3
|
+
> Sign and execute a transaction 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 dApp.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
const dAppKit = createDAppKit({
|
|
12
|
+
/* config */
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const tx = new Transaction();
|
|
16
|
+
// No need to manually set sender - it's done automatically
|
|
17
|
+
tx.transferObjects([coinWithBalance({ balance: 123 })], '0xrecipient...');
|
|
18
|
+
|
|
19
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
20
|
+
transaction: tx,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (result.FailedTransaction) {
|
|
24
|
+
throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log('Transaction digest:', result.Transaction.digest);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Parameters
|
|
31
|
+
|
|
32
|
+
- **`transaction`** - `Transaction | string` - The transaction to sign and execute. Can be either a
|
|
33
|
+
Transaction instance or base64-encoded bcs bytes for the transaction.
|
|
34
|
+
- **`signal`** (optional) - `AbortSignal` - An abort signal to cancel the transaction request.
|
|
35
|
+
|
|
36
|
+
## Return Value
|
|
37
|
+
|
|
38
|
+
Returns a `Promise` that resolves to a `TransactionResult` discriminated union:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
type TransactionResult =
|
|
42
|
+
| { $kind: 'Transaction'; Transaction: Transaction }
|
|
43
|
+
| { $kind: 'FailedTransaction'; FailedTransaction: Transaction };
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `Transaction` object contains:
|
|
47
|
+
|
|
48
|
+
- **`digest`** - `string` - The transaction digest (unique identifier for the executed transaction)
|
|
49
|
+
- **`signatures`** - `string[]` - The signatures as base64-encoded strings
|
|
50
|
+
- **`epoch`** - `string | null` - The epoch in which the transaction was executed
|
|
51
|
+
- **`status`** - `ExecutionStatus` - The execution status with `success: boolean` and
|
|
52
|
+
`error: string | null`
|
|
53
|
+
- **`effects`** - `TransactionEffects | null` - The parsed transaction effects (may be `null` if
|
|
54
|
+
effects parsing fails for unknown effect versions)
|
|
55
|
+
- **`transaction`** - `TransactionData` - The parsed transaction data
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const result = await dAppKit.signAndExecuteTransaction({ transaction });
|
|
59
|
+
|
|
60
|
+
if (result.FailedTransaction) {
|
|
61
|
+
console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Access the successful transaction results
|
|
66
|
+
const tx = result.Transaction;
|
|
67
|
+
console.log('Digest:', tx.digest);
|
|
68
|
+
console.log('Signatures:', tx.signatures);
|
|
69
|
+
console.log('Epoch:', tx.epoch);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Transaction Building
|
|
73
|
+
|
|
74
|
+
When passing a Transaction instance, the action automatically:
|
|
75
|
+
|
|
76
|
+
1. Sets the sender address if not already set
|
|
77
|
+
2. Builds the transaction using the current network's client
|
|
78
|
+
3. Converts it to the appropriate format for the wallet
|
|
79
|
+
4. Submits the transaction to the network
|
|
80
|
+
|
|
81
|
+
## Wallet Compatibility
|
|
82
|
+
|
|
83
|
+
- The action transparently handles both `sui:signAndExecuteTransaction` and
|
|
84
|
+
`sui:signAndExecuteTransactionBlock` wallet-standard features
|
|
85
|
+
- The wallet handles network submission and response
|
|
86
|
+
- Some wallets (Enoki, Enoki Connect, WalletConnect) may use the dApp Kit client and execute
|
|
87
|
+
transactions within the application as an implementation detail
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// The action automatically detects and uses the appropriate method
|
|
91
|
+
// No special configuration needed
|
|
92
|
+
const result = await dAppKit.signAndExecuteTransaction({
|
|
93
|
+
transaction: tx,
|
|
94
|
+
});
|
|
95
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Sign Personal Message
|
|
2
|
+
|
|
3
|
+
> Sign an arbitrary message with the connected wallet
|
|
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
|
+
const dAppKit = createDAppKit({
|
|
13
|
+
/* config */
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const message = new TextEncoder().encode('Please sign this message');
|
|
17
|
+
const result = await dAppKit.signPersonalMessage({
|
|
18
|
+
message,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log('Message bytes:', result.bytes);
|
|
22
|
+
console.log('Signature:', result.signature);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Parameters
|
|
26
|
+
|
|
27
|
+
- **`message`** - `Uint8Array` - The message to sign as a byte array
|
|
28
|
+
|
|
29
|
+
## Return Value
|
|
30
|
+
|
|
31
|
+
Returns a `Promise` that resolves to an object containing:
|
|
32
|
+
|
|
33
|
+
- **`bytes`** - `string` - Base64 encoded message bytes
|
|
34
|
+
- **`signature`** - `string` - Base64 encoded signature
|
|
35
|
+
|
|
36
|
+
## Message Format
|
|
37
|
+
|
|
38
|
+
The message parameter must be a `Uint8Array`. Common patterns for creating byte arrays:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const textMessage = new TextEncoder().encode('Hello, Sui!');
|
|
42
|
+
await dAppKit.signPersonalMessage({ message: textMessage });
|
|
43
|
+
|
|
44
|
+
const jsonMessage = new TextEncoder().encode(
|
|
45
|
+
JSON.stringify({ action: 'sign', timestamp: Date.now() }),
|
|
46
|
+
);
|
|
47
|
+
await dAppKit.signPersonalMessage({ message: jsonMessage });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Security Considerations
|
|
51
|
+
|
|
52
|
+
### Message Content
|
|
53
|
+
|
|
54
|
+
- Always display the message content clearly to users before signing
|
|
55
|
+
- Avoid signing opaque or encoded data that users cannot understand
|
|
56
|
+
- Include human-readable prefixes for different message types
|
|
57
|
+
- Consider adding timestamps to prevent replay attacks
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Sign Transaction
|
|
2
|
+
|
|
3
|
+
> Sign a transaction without executing it
|
|
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
|
+
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
|
+
// Sign the transaction without executing it
|
|
21
|
+
const { bytes, signature } = await dAppKit.signTransaction({
|
|
22
|
+
transaction: tx,
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Parameters
|
|
27
|
+
|
|
28
|
+
- **`transaction`** - `Transaction | string` - The transaction to sign. Can be either a Transaction
|
|
29
|
+
instance or base64-encoded bcs bytes for the transaction.
|
|
30
|
+
- **`signal`** (optional) - `AbortSignal` - An abort signal to cancel the signing request.
|
|
31
|
+
|
|
32
|
+
## Return Value
|
|
33
|
+
|
|
34
|
+
Returns a `Promise` that resolves to an object containing:
|
|
35
|
+
|
|
36
|
+
- **`bytes`** - `string` - The signed transaction as a base64-encoded BCS string
|
|
37
|
+
- **`signature`** - `string` - The signature as a base64-encoded string
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const result = await dAppKit.signTransaction({ transaction });
|
|
41
|
+
console.log('Signed transaction bytes:', result.bytes);
|
|
42
|
+
console.log('Signature:', result.signature);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Transaction Building
|
|
46
|
+
|
|
47
|
+
When passing a Transaction instance, the action automatically:
|
|
48
|
+
|
|
49
|
+
1. Sets the sender address if not already set
|
|
50
|
+
2. Builds the transaction using the current network's client
|
|
51
|
+
3. Converts it to the appropriate format for the wallet
|
|
52
|
+
|
|
53
|
+
## Wallet Compatibility
|
|
54
|
+
|
|
55
|
+
- The action transparently handles both `sui:signTransaction` and `sui:signTransactionBlock`
|
|
56
|
+
wallet-standard features
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// The action automatically detects and uses the appropriate method
|
|
60
|
+
// No special configuration needed
|
|
61
|
+
const result = await dAppKit.signTransaction({
|
|
62
|
+
transaction: tx,
|
|
63
|
+
});
|
|
64
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Switch Account
|
|
2
|
+
|
|
3
|
+
> Switch the active account in the connected wallet
|
|
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
|
|
9
|
+
> your application. Changing the active account in the dApp does not affect the wallet itself, and
|
|
10
|
+
> wallets 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
|
+
const dAppKit = createDAppKit({
|
|
20
|
+
/* config */
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Switch to a different account
|
|
24
|
+
dAppKit.switchAccount({
|
|
25
|
+
account: anotherAccount, // UiWalletAccount from the connected wallet
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Parameters
|
|
30
|
+
|
|
31
|
+
- **`account`** - `UiWalletAccount` - The account to switch to. Must be an account that belongs to
|
|
32
|
+
the currently connected wallet.
|
|
33
|
+
|
|
34
|
+
## Return Value
|
|
35
|
+
|
|
36
|
+
Returns `void`. The action completes synchronously and updates the connection state immediately.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Switch Network
|
|
2
|
+
|
|
3
|
+
> Switch the active network for the dApp Kit instance
|
|
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 dApp's client connection. The wallet itself is not
|
|
9
|
+
> affected by this change, and wallets are not notified when the network changes in the dApp.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const GRPC_URLS = {
|
|
15
|
+
mainnet: 'https://fullnode.mainnet.sui.io:443',
|
|
16
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
const dAppKit = createDAppKit({
|
|
20
|
+
networks: ['mainnet', 'testnet'],
|
|
21
|
+
defaultNetwork: 'mainnet',
|
|
22
|
+
createClient: (network) => new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] }),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Switch to a different network
|
|
26
|
+
dAppKit.switchNetwork('testnet');
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Parameters
|
|
30
|
+
|
|
31
|
+
- **`network`** - `TNetworks[number]` - The network to switch to. Must be one of the networks
|
|
32
|
+
configured when creating the dApp Kit instance.
|
|
33
|
+
|
|
34
|
+
## Return Value
|
|
35
|
+
|
|
36
|
+
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 dApp. 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 dApp 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#1-create-a-dapp-kit-instance) once,
|
|
27
|
+
> and all hooks will be properly typed
|
|
28
|
+
> 2. Pass the dAppKit instance explicitly to each hook: `useWalletConnection({ dAppKit })`
|
|
29
|
+
|
|
30
|
+
This instance provides:
|
|
31
|
+
|
|
32
|
+
- Wallet connection management
|
|
33
|
+
- Network switching capabilities
|
|
34
|
+
- Client access for blockchain interactions
|
|
35
|
+
- State stores for reactive updates
|
|
36
|
+
|
|
37
|
+
## Parameters
|
|
38
|
+
|
|
39
|
+
- **autoConnect** (optional) - Enables automatically connecting to the most recently used wallet
|
|
40
|
+
account (default: `true`)
|
|
41
|
+
- **networks** - A list of networks supported by the application (e.g. `['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
|
+
```
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# @mysten/create-dapp
|
|
2
|
+
|
|
3
|
+
> Create a Sui dApp with one command
|
|
4
|
+
|
|
5
|
+
`@mysten/create-dapp` is a CLI tool that scaffolds a complete Sui dApp project with best practices
|
|
6
|
+
built in.
|
|
7
|
+
|
|
8
|
+
## Quick Start
|
|
9
|
+
|
|
10
|
+
```sh npm2yarn
|
|
11
|
+
npm create @mysten/dapp
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The CLI prompts you to choose a template and project name, then creates a ready-to-run project.
|
|
15
|
+
|
|
16
|
+
## Templates
|
|
17
|
+
|
|
18
|
+
### react-client-dapp
|
|
19
|
+
|
|
20
|
+
A basic React dApp that demonstrates wallet connection and fetching owned objects:
|
|
21
|
+
|
|
22
|
+
- Wallet connection with `ConnectButton`
|
|
23
|
+
- Display connected wallet address
|
|
24
|
+
- List objects owned by the connected wallet
|
|
25
|
+
- Clean, modern UI with Tailwind CSS
|
|
26
|
+
|
|
27
|
+
### react-e2e-counter
|
|
28
|
+
|
|
29
|
+
A complete end-to-end example with Move smart contract integration:
|
|
30
|
+
|
|
31
|
+
- Move counter contract in `move/counter/`
|
|
32
|
+
- TypeScript bindings generated with `@mysten/codegen`
|
|
33
|
+
- Create, increment, and reset counters
|
|
34
|
+
- MVR (Move Registry) name resolution for package IDs
|
|
35
|
+
- Full transaction signing and execution
|
|
36
|
+
|
|
37
|
+
## Tech Stack
|
|
38
|
+
|
|
39
|
+
Both templates include:
|
|
40
|
+
|
|
41
|
+
- [React](https://react.dev/) - UI framework
|
|
42
|
+
- [TypeScript](https://www.typescriptlang.org/) - Type safety
|
|
43
|
+
- [Vite](https://vitejs.dev/) - Fast build tooling
|
|
44
|
+
- [Tailwind CSS v4](https://tailwindcss.com/) - Utility-first styling
|
|
45
|
+
- [Lucide React](https://lucide.dev/) - Modern icons
|
|
46
|
+
- [`@mysten/dapp-kit-react`](/dapp-kit) - Wallet connection and blockchain interaction
|
|
47
|
+
- [pnpm](https://pnpm.io/) - Package management
|
|
48
|
+
|
|
49
|
+
The e2e-counter template also includes:
|
|
50
|
+
|
|
51
|
+
- [`@mysten/codegen`](/codegen) - Generate TypeScript from Move code
|
|
52
|
+
|
|
53
|
+
## Project Structure
|
|
54
|
+
|
|
55
|
+
### react-client-dapp
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
src/
|
|
59
|
+
├── components/ui/ # Reusable UI components (Card)
|
|
60
|
+
├── lib/utils.ts # Utility functions
|
|
61
|
+
├── App.tsx # Main application
|
|
62
|
+
├── WalletStatus.tsx # Wallet connection display
|
|
63
|
+
├── OwnedObjects.tsx # Object list component
|
|
64
|
+
├── dApp-kit.ts # dApp Kit configuration
|
|
65
|
+
└── index.css # Tailwind CSS theme
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### react-e2e-counter
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
src/
|
|
72
|
+
├── components/ui/ # UI components (Button, Card)
|
|
73
|
+
├── contracts/ # Generated TypeScript bindings
|
|
74
|
+
├── lib/utils.ts # Utility functions
|
|
75
|
+
├── App.tsx # Main application
|
|
76
|
+
├── Counter.tsx # Counter display and controls
|
|
77
|
+
├── CreateCounter.tsx # Counter creation
|
|
78
|
+
├── dApp-kit.ts # dApp Kit configuration
|
|
79
|
+
├── constants.ts # Package IDs per network
|
|
80
|
+
└── index.css # Tailwind CSS theme
|
|
81
|
+
move/
|
|
82
|
+
└── counter/ # Move smart contract
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Using the e2e-counter Template
|
|
86
|
+
|
|
87
|
+
### 1. Deploy the Move Contract
|
|
88
|
+
|
|
89
|
+
First, install the [Sui CLI](https://docs.sui.io/build/install) and set up testnet:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
sui client new-env --alias testnet --rpc https://fullnode.testnet.sui.io:443
|
|
93
|
+
sui client switch --env testnet
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Get testnet SUI from the [faucet](https://faucet.sui.io), then publish:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
cd move
|
|
100
|
+
sui client publish --gas-budget 100000000 counter
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 2. Configure the Package ID
|
|
104
|
+
|
|
105
|
+
Copy the `packageId` from the publish output to `src/constants.ts`:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3. Generate TypeScript Bindings
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pnpm codegen
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This generates type-safe functions in `src/contracts/` for interacting with your Move modules.
|
|
118
|
+
|
|
119
|
+
### 4. Start Development
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pnpm install
|
|
123
|
+
pnpm dev
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Customizing the UI
|
|
127
|
+
|
|
128
|
+
The templates use [Tailwind CSS v4](https://tailwindcss.com/docs) with
|
|
129
|
+
[shadcn/ui](https://ui.shadcn.com/)-style components. The UI components in `src/components/ui/` can
|
|
130
|
+
be customized or extended.
|
|
131
|
+
|
|
132
|
+
To add more components, copy them from the
|
|
133
|
+
[shadcn/ui components](https://ui.shadcn.com/docs/components) documentation and adapt them to your
|
|
134
|
+
project.
|
|
135
|
+
|
|
136
|
+
Theme variables are defined in `src/index.css` using Tailwind's `@theme` directive.
|
|
137
|
+
|
|
138
|
+
## CLI Options
|
|
139
|
+
|
|
140
|
+
You can skip prompts with command-line flags:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Create with specific template
|
|
144
|
+
npm create @mysten/dapp -- -t react-e2e-counter
|
|
145
|
+
|
|
146
|
+
# Create with specific name
|
|
147
|
+
npm create @mysten/dapp -- -n my-app
|
|
148
|
+
|
|
149
|
+
# Create with both
|
|
150
|
+
npm create @mysten/dapp -- -t react-client-dapp -n my-app
|
|
151
|
+
```
|