@mysten/dapp-kit 1.0.2 → 1.0.4
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 +22 -0
- package/docs/index.md +91 -0
- package/docs/llms-index.md +27 -0
- package/docs/rpc-hooks.md +161 -0
- package/docs/slush.md +29 -0
- package/docs/sui-client-provider.md +191 -0
- package/docs/themes.md +115 -0
- package/docs/wallet-components/ConnectButton.md +22 -0
- package/docs/wallet-components/ConnectModal.md +66 -0
- package/docs/wallet-hooks/useAccounts.md +36 -0
- package/docs/wallet-hooks/useAutoConnectWallet.md +29 -0
- package/docs/wallet-hooks/useConnectWallet.md +48 -0
- package/docs/wallet-hooks/useCurrentAccount.md +36 -0
- package/docs/wallet-hooks/useCurrentWallet.md +59 -0
- package/docs/wallet-hooks/useDisconnectWallet.md +26 -0
- package/docs/wallet-hooks/useSignAndExecuteTransaction.md +124 -0
- package/docs/wallet-hooks/useSignPersonalMessage.md +59 -0
- package/docs/wallet-hooks/useSignTransaction.md +67 -0
- package/docs/wallet-hooks/useSwitchAccount.md +47 -0
- package/docs/wallet-hooks/useWallets.md +38 -0
- package/docs/wallet-provider.md +37 -0
- package/package.json +10 -7
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# ConnectModal
|
|
2
|
+
|
|
3
|
+
> React connect modal component
|
|
4
|
+
|
|
5
|
+
ControlledConnectModalExample, UncontrolledConnectModalExample, } from
|
|
6
|
+
'../../../../examples/wallet-components-client';
|
|
7
|
+
|
|
8
|
+
The `ConnectModal` component opens a modal that guides the user through connecting their wallet to
|
|
9
|
+
the dApp.
|
|
10
|
+
|
|
11
|
+
## Controlled example
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
|
|
15
|
+
const currentAccount = useCurrentAccount();
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ConnectModal
|
|
20
|
+
trigger={
|
|
21
|
+
<button disabled={!!currentAccount}> {currentAccount ? 'Connected' : 'Connect'}</button>
|
|
22
|
+
}
|
|
23
|
+
open={open}
|
|
24
|
+
onOpenChange={(isOpen) => setOpen(isOpen)}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Click **Connect** to connect your wallet and see the previous code in action:
|
|
31
|
+
|
|
32
|
+
## Uncontrolled example
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
|
|
36
|
+
const currentAccount = useCurrentAccount();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ConnectModal
|
|
40
|
+
trigger={
|
|
41
|
+
<button disabled={!!currentAccount}> {currentAccount ? 'Connected' : 'Connect'}</button>
|
|
42
|
+
}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Click **Connect** to connect your wallet and see the previous code in action:
|
|
49
|
+
|
|
50
|
+
## Controlled props
|
|
51
|
+
|
|
52
|
+
- `open` - The controlled open state of the dialog.
|
|
53
|
+
- `onOpenChange` - Event handler called when the open state of the dialog changes.
|
|
54
|
+
- `trigger` - The trigger button that opens the dialog.
|
|
55
|
+
- `walletFilter` - A filter function that receives a wallet instance, and returns a boolean
|
|
56
|
+
indicating whether the wallet should be displayed in the wallet list. By default, all wallets are
|
|
57
|
+
displayed.
|
|
58
|
+
|
|
59
|
+
## Uncontrolled props
|
|
60
|
+
|
|
61
|
+
- `defaultOpen` - The open state of the dialog when it is initially rendered. Use when you do not
|
|
62
|
+
need to control its open state.
|
|
63
|
+
- `trigger` - The trigger button that opens the dialog.
|
|
64
|
+
- `walletFilter` - A filter function that receives a wallet instance, and returns a boolean
|
|
65
|
+
indicating whether the wallet should be displayed in the wallet list. By default, all wallets are
|
|
66
|
+
displayed.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# useAccounts
|
|
2
|
+
|
|
3
|
+
> List wallet accounts
|
|
4
|
+
|
|
5
|
+
The `useAccounts` hook retrieves a list of connected accounts the dApp authorizes.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const accounts = useAccounts();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
<h2>Available accounts:</h2>
|
|
16
|
+
{accounts.length === 0 && <div>No accounts detected</div>}
|
|
17
|
+
<ul>
|
|
18
|
+
{accounts.map((account) => (
|
|
19
|
+
<li key={account.address}>- {account.address}</li>
|
|
20
|
+
))}
|
|
21
|
+
</ul>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
## Account properties
|
|
30
|
+
|
|
31
|
+
- `address`: The address of the account, corresponding with a public key.
|
|
32
|
+
- `publicKey`: The public key of the account, represented as a `Uint8Array`.
|
|
33
|
+
- `chains`: The chains the account supports.
|
|
34
|
+
- `features`: The features the account supports.
|
|
35
|
+
- `label`: An optional user-friendly descriptive label or name for the account.
|
|
36
|
+
- `icon`: An optional user-friendly icon for the account.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# useAutoConnectWallet
|
|
2
|
+
|
|
3
|
+
> Automatically reconnect to the last connected wallet
|
|
4
|
+
|
|
5
|
+
The `useAutoConnectWallet` hook retrieves the status for the initial wallet auto-connection process.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const autoConnectionStatus = useAutoConnectWallet();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
<div>Auto-connection status: {autoConnectionStatus}</div>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
## Auto-connection status properties
|
|
24
|
+
|
|
25
|
+
- `disabled` - When the auto-connection functionality is disabled.
|
|
26
|
+
- `idle` - When the initial auto-connection attempt hasn't been made yet.
|
|
27
|
+
- `attempted` - When an auto-connection attempt has been made. This means either that there is no
|
|
28
|
+
previously connected wallet, the previously connected wallet was not found, or that it has
|
|
29
|
+
successfully connected to a wallet.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# useConnectWallet
|
|
2
|
+
|
|
3
|
+
> Connect a wallet to the dApp
|
|
4
|
+
|
|
5
|
+
The `useConnectWallet` hook is a mutation hook for establishing a connection to a specific wallet.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const wallets = useWallets();
|
|
11
|
+
const { mutate: connect } = useConnectWallet();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div style={{ padding: 20 }}>
|
|
15
|
+
<ConnectButton />
|
|
16
|
+
<ul>
|
|
17
|
+
{wallets.map((wallet) => (
|
|
18
|
+
<li key={wallet.name}>
|
|
19
|
+
<button
|
|
20
|
+
onClick={() => {
|
|
21
|
+
connect(
|
|
22
|
+
{ wallet },
|
|
23
|
+
{
|
|
24
|
+
onSuccess: () => console.log('connected'),
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
Connect to {wallet.name}
|
|
30
|
+
</button>
|
|
31
|
+
</li>
|
|
32
|
+
))}
|
|
33
|
+
</ul>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
## Connect arguments
|
|
42
|
+
|
|
43
|
+
- `args` - Arguments passed to the `connect` function of the wallet.
|
|
44
|
+
- `wallet` - The wallet to connect to.
|
|
45
|
+
- `accountAddress` - (optional) The address in the wallet to connect to.
|
|
46
|
+
|
|
47
|
+
- `options` - Options passed the `useMutation` hook from
|
|
48
|
+
[@tanstack/react-query](https://tanstack.com/query/latest/docs/react/guides/mutations).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# useCurrentAccount
|
|
2
|
+
|
|
3
|
+
> Get the current wallet account
|
|
4
|
+
|
|
5
|
+
The `useCurrentAccount` hook retrieves the wallet account that is currently selected, if one exists.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const account = useCurrentAccount();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
{!account && <div>No account connected</div>}
|
|
16
|
+
{account && (
|
|
17
|
+
<div>
|
|
18
|
+
<h2>Current account:</h2>
|
|
19
|
+
<div>Address: {account.address}</div>
|
|
20
|
+
</div>
|
|
21
|
+
)}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
## Account properties
|
|
30
|
+
|
|
31
|
+
- `address`: The address of the account, corresponding with a public key.
|
|
32
|
+
- `publicKey`: The public key of the account, represented as a `Uint8Array`.
|
|
33
|
+
- `chains`: The chains the account supports.
|
|
34
|
+
- `features`: The features the account supports.
|
|
35
|
+
- `label`: An optional user-friendly descriptive label or name for the account.
|
|
36
|
+
- `icon`: An optional user-friendly icon for the account.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# useCurrentWallet
|
|
2
|
+
|
|
3
|
+
> Get the current wallet connection
|
|
4
|
+
|
|
5
|
+
The `useCurrentWallet` hook retrieves the wallet that is currently connected to the dApp, if one
|
|
6
|
+
exists.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
|
|
10
|
+
function MyComponent() {
|
|
11
|
+
const { currentWallet, connectionStatus } = useCurrentWallet();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<ConnectButton />
|
|
16
|
+
{connectionStatus === 'connected' ? (
|
|
17
|
+
<div>
|
|
18
|
+
<h2>Current wallet:</h2>
|
|
19
|
+
<div>Name: {currentWallet.name}</div>
|
|
20
|
+
<div>
|
|
21
|
+
Accounts:
|
|
22
|
+
<ul>
|
|
23
|
+
{currentWallet.accounts.map((account) => (
|
|
24
|
+
<li key={account.address}>- {account.address}</li>
|
|
25
|
+
))}
|
|
26
|
+
</ul>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
) : (
|
|
30
|
+
<div>Connection status: {connectionStatus}</div>
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
## Wallet properties
|
|
40
|
+
|
|
41
|
+
- `name` - The name of the wallet.
|
|
42
|
+
- `version` - The version of the wallet as a string.
|
|
43
|
+
- `icon` - A data URL of the wallet icon as an SVG.
|
|
44
|
+
- `accounts` - An array of accounts that are available in the wallet.
|
|
45
|
+
- `features` - An object with all the
|
|
46
|
+
[wallet-standard](https://github.com/wallet-standard/wallet-standard) features implemented by the
|
|
47
|
+
wallet.
|
|
48
|
+
- `chains` - An array of chain identifiers that the wallet supports.
|
|
49
|
+
|
|
50
|
+
## Connection status properties
|
|
51
|
+
|
|
52
|
+
- `connectionStatus`
|
|
53
|
+
- `disconnected` - When no wallet is connected to the dApp.
|
|
54
|
+
- `connecting` - When a wallet connection attempt is in progress.
|
|
55
|
+
- `connected` - When a wallet is connected to the dApp.
|
|
56
|
+
|
|
57
|
+
- `isDisconnected` - A derived boolean from the status variable above, provided for convenience.
|
|
58
|
+
- `isConnecting` - A derived boolean from the status variable above, provided for convenience.
|
|
59
|
+
- `isConnected` - A derived boolean from the status variable above, provided for convenience.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# useDisconnectWallet
|
|
2
|
+
|
|
3
|
+
> Disconnect the current wallet
|
|
4
|
+
|
|
5
|
+
The `useDisconnectWallet` hook is a mutation hook for disconnecting from an active wallet
|
|
6
|
+
connection, if currently connected.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
|
|
10
|
+
function MyComponent() {
|
|
11
|
+
const { mutate: disconnect } = useDisconnectWallet();
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<ConnectButton />
|
|
15
|
+
|
|
16
|
+
<button onClick={() => disconnect()}>Disconnect</button>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
## Arguments
|
|
25
|
+
|
|
26
|
+
There are no arguments for `useDisconnectWallet`.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# useSignAndExecuteTransaction
|
|
2
|
+
|
|
3
|
+
> Sign and execute a transaction
|
|
4
|
+
|
|
5
|
+
Use the `useSignAndExecuteTransaction` hook to prompt the user to sign and execute a transaction
|
|
6
|
+
block with their wallet.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
|
|
10
|
+
function MyComponent() {
|
|
11
|
+
const { mutate: signAndExecuteTransaction } = useSignAndExecuteTransaction();
|
|
12
|
+
const [digest, setDigest] = useState('');
|
|
13
|
+
const currentAccount = useCurrentAccount();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div style={{ padding: 20 }}>
|
|
17
|
+
<ConnectButton />
|
|
18
|
+
{currentAccount && (
|
|
19
|
+
<>
|
|
20
|
+
<div>
|
|
21
|
+
<button
|
|
22
|
+
onClick={() => {
|
|
23
|
+
signAndExecuteTransaction(
|
|
24
|
+
{
|
|
25
|
+
transaction: new Transaction(),
|
|
26
|
+
chain: 'sui:devnet',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
onSuccess: (result) => {
|
|
30
|
+
console.log('executed transaction', result);
|
|
31
|
+
setDigest(result.digest);
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
Sign and execute transaction
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
<div>Digest: {digest}</div>
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Example
|
|
49
|
+
|
|
50
|
+
## Return additional data, or executing through GraphQL
|
|
51
|
+
|
|
52
|
+
To customize how transactions are executed, and what data is returned when executing a transaction,
|
|
53
|
+
you can pass a custom `execute` function.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
|
|
57
|
+
ConnectButton,
|
|
58
|
+
useSuiClient,
|
|
59
|
+
useCurrentAccount,
|
|
60
|
+
useSignAndExecuteTransaction,
|
|
61
|
+
} from '@mysten/dapp-kit';
|
|
62
|
+
|
|
63
|
+
function MyComponent() {
|
|
64
|
+
const client = useSuiClient();
|
|
65
|
+
const { mutate: signAndExecuteTransaction } = useSignAndExecuteTransaction({
|
|
66
|
+
execute: async ({ bytes, signature }) =>
|
|
67
|
+
await client.executeTransactionBlock({
|
|
68
|
+
transactionBlock: bytes,
|
|
69
|
+
signature,
|
|
70
|
+
options: {
|
|
71
|
+
// Raw effects are required so the effects can be reported back to the wallet
|
|
72
|
+
showRawEffects: true,
|
|
73
|
+
// Select additional data to return
|
|
74
|
+
showObjectChanges: true,
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const [digest, setDigest] = useState('');
|
|
80
|
+
const currentAccount = useCurrentAccount();
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div style={{ padding: 20 }}>
|
|
84
|
+
<ConnectButton />
|
|
85
|
+
{currentAccount && (
|
|
86
|
+
<>
|
|
87
|
+
<div>
|
|
88
|
+
<button
|
|
89
|
+
onClick={() => {
|
|
90
|
+
signAndExecuteTransaction(
|
|
91
|
+
{
|
|
92
|
+
transaction: new Transaction(),
|
|
93
|
+
chain: 'sui:devnet',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
onSuccess: (result) => {
|
|
97
|
+
console.log('object changes', result.objectChanges);
|
|
98
|
+
setDigest(result.digest);
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
Sign and execute transaction
|
|
105
|
+
</button>
|
|
106
|
+
</div>
|
|
107
|
+
<div>Digest: {digest}</div>
|
|
108
|
+
</>
|
|
109
|
+
)}
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Arguments
|
|
116
|
+
|
|
117
|
+
- `transaction`: The transaction to sign and execute.
|
|
118
|
+
- `chain`: (optional) The chain identifier the transaction should be signed for. Defaults to the
|
|
119
|
+
active network of the dApp.
|
|
120
|
+
- `execute`: (optional) A custom function to execute the transaction
|
|
121
|
+
|
|
122
|
+
In addition to these options, you can also pass any options that the
|
|
123
|
+
[SuiJsonRpcClient.signAndExecuteTransaction](/typedoc/classes/_mysten_sui.client.SuiJsonRpcClient.html#signAndExecuteTransactionBlock)
|
|
124
|
+
method accepts.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# useSignPersonalMessage
|
|
2
|
+
|
|
3
|
+
> Sign a personal message with the connected wallet
|
|
4
|
+
|
|
5
|
+
Use the `useSignPersonalMessage` hook to prompt the user to sign a message with their wallet.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const { mutate: signPersonalMessage } = useSignPersonalMessage();
|
|
11
|
+
const [message, setMessage] = useState('hello, World!');
|
|
12
|
+
const [signature, setSignature] = useState('');
|
|
13
|
+
const currentAccount = useCurrentAccount();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div style={{ padding: 20 }}>
|
|
17
|
+
<ConnectButton />
|
|
18
|
+
{currentAccount && (
|
|
19
|
+
<>
|
|
20
|
+
<div>
|
|
21
|
+
<label>
|
|
22
|
+
Message:{' '}
|
|
23
|
+
<input type="text" value={message} onChange={(ev) => setMessage(ev.target.value)} />
|
|
24
|
+
</label>
|
|
25
|
+
</div>
|
|
26
|
+
<button
|
|
27
|
+
onClick={() => {
|
|
28
|
+
signPersonalMessage(
|
|
29
|
+
{
|
|
30
|
+
message: new TextEncoder().encode(message),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
onSuccess: (result) => setSignature(result.signature),
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
Sign message
|
|
39
|
+
</button>
|
|
40
|
+
<div>Signature: {signature}</div>
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Example
|
|
49
|
+
|
|
50
|
+
## Arguments
|
|
51
|
+
|
|
52
|
+
- `message`: The message to sign, as a `Uint8Array`.
|
|
53
|
+
- `chain`: (optional) The chain identifier the message should be signed for. Defaults to the active
|
|
54
|
+
network of the dApp.
|
|
55
|
+
|
|
56
|
+
## Result
|
|
57
|
+
|
|
58
|
+
- `signature`: The signature of the message, as a `Base64`-encoded `string`.
|
|
59
|
+
- `bytes`: The bytes of the message, as a `Base64`-encoded `string`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# useSignTransaction
|
|
2
|
+
|
|
3
|
+
> Sign a transaction without executing it
|
|
4
|
+
|
|
5
|
+
Use the `useSignTransaction` hook to prompt the user to sign a transaction with their wallet.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
ConnectButton,
|
|
10
|
+
useCurrentAccount,
|
|
11
|
+
useSignTransaction,
|
|
12
|
+
useSuiClient,
|
|
13
|
+
} from '@mysten/dapp-kit';
|
|
14
|
+
|
|
15
|
+
function MyComponent() {
|
|
16
|
+
const { mutateAsync: signTransaction } = useSignTransaction();
|
|
17
|
+
const [signature, setSignature] = useState('');
|
|
18
|
+
const client = useSuiClient();
|
|
19
|
+
const currentAccount = useCurrentAccount();
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div style={{ padding: 20 }}>
|
|
23
|
+
<ConnectButton />
|
|
24
|
+
{currentAccount && (
|
|
25
|
+
<>
|
|
26
|
+
<div>
|
|
27
|
+
<button
|
|
28
|
+
onClick={async () => {
|
|
29
|
+
const { bytes, signature } = await signTransaction({
|
|
30
|
+
transaction: new Transaction(),
|
|
31
|
+
chain: 'sui:devnet',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const executeResult = await client.executeTransactionBlock({
|
|
35
|
+
transactionBlock: bytes,
|
|
36
|
+
signature,
|
|
37
|
+
options: {
|
|
38
|
+
showRawEffects: true,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
console.log(executeResult);
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
Sign empty transaction
|
|
46
|
+
</button>
|
|
47
|
+
</div>
|
|
48
|
+
<div>Signature: {signature}</div>
|
|
49
|
+
</>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Example
|
|
57
|
+
|
|
58
|
+
## Arguments
|
|
59
|
+
|
|
60
|
+
- `transactionBlock`: The transaction to sign.
|
|
61
|
+
- `chain`: (optional) The chain identifier the transaction should be signed for. Defaults to the
|
|
62
|
+
active network of the dApp.
|
|
63
|
+
|
|
64
|
+
## Result
|
|
65
|
+
|
|
66
|
+
- `signature`: The signature of the message, as a Base64-encoded `string`.
|
|
67
|
+
- `bytes`: The serialized transaction bytes, as a Base64-encoded `string`.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# useSwitchAccount
|
|
2
|
+
|
|
3
|
+
> Switch the active wallet account
|
|
4
|
+
|
|
5
|
+
The `useSwitchAccount` hook is a mutation hook for establishing a connection to a specific wallet.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
|
|
9
|
+
function MyComponent() {
|
|
10
|
+
const { mutate: switchAccount } = useSwitchAccount();
|
|
11
|
+
const accounts = useAccounts();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div style={{ padding: 20 }}>
|
|
15
|
+
<ConnectButton />
|
|
16
|
+
<ul>
|
|
17
|
+
{accounts.map((account) => (
|
|
18
|
+
<li key={account.address}>
|
|
19
|
+
<button
|
|
20
|
+
onClick={() => {
|
|
21
|
+
switchAccount(
|
|
22
|
+
{ account },
|
|
23
|
+
{
|
|
24
|
+
onSuccess: () => console.log(`switched to ${account.address}`),
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
Switch to {account.address}
|
|
30
|
+
</button>
|
|
31
|
+
</li>
|
|
32
|
+
))}
|
|
33
|
+
</ul>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
## Arguments
|
|
42
|
+
|
|
43
|
+
- `args` - Arguments passed to the `connect` function of the wallet.
|
|
44
|
+
- `account` - The account to switch to.
|
|
45
|
+
|
|
46
|
+
- `options` - Options passed the `useMutation` hook from
|
|
47
|
+
[@tanstack/react-query](https://tanstack.com/query/latest/docs/react/guides/mutations).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# useWallets
|
|
2
|
+
|
|
3
|
+
> List available wallet extensions
|
|
4
|
+
|
|
5
|
+
The `useWallets` hook returns an array of wallets that are available to the user. The wallets are
|
|
6
|
+
sorted by their priority, with the highest priority wallet being the first in the array.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
|
|
10
|
+
function MyComponent() {
|
|
11
|
+
const wallets = useWallets();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<h2>Installed wallets</h2>
|
|
16
|
+
{wallets.length === 0 && <div>No wallets installed</div>}
|
|
17
|
+
<ul>
|
|
18
|
+
{wallets.map((wallet) => (
|
|
19
|
+
<li key={wallet.name}>{wallet.name}</li>
|
|
20
|
+
))}
|
|
21
|
+
</ul>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
## Wallet properties
|
|
30
|
+
|
|
31
|
+
- `name` - The name of the wallet.
|
|
32
|
+
- `version` - The version of the wallet as a string.
|
|
33
|
+
- `icon` - A data URL of the wallet icon as an SVG.
|
|
34
|
+
- `accounts` - An array of accounts that are available in the wallet.
|
|
35
|
+
- `features` - An object with all the
|
|
36
|
+
[wallet-standard](https://github.com/wallet-standard/wallet-standard) features implemented by the
|
|
37
|
+
wallet.
|
|
38
|
+
- `chains` - An array of chain identifiers that the wallet supports.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# WalletProvider
|
|
2
|
+
|
|
3
|
+
> React provider for wallet connections
|
|
4
|
+
|
|
5
|
+
Use `WalletProvider` to set up the necessary context for your React app. Use it at the root of your
|
|
6
|
+
app, so that you can use any of the dApp Kit wallet components underneath it.
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
function App() {
|
|
10
|
+
return (
|
|
11
|
+
<WalletProvider>
|
|
12
|
+
<YourApp />
|
|
13
|
+
</WalletProvider>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The `WalletProvider` manages all wallet state for you, and makes the current wallet state available
|
|
19
|
+
to other dApp Kit hooks and components.
|
|
20
|
+
|
|
21
|
+
### Props
|
|
22
|
+
|
|
23
|
+
All props are optional.
|
|
24
|
+
|
|
25
|
+
- `preferredWallets` - A list of wallets that are sorted to the top of the wallet list.
|
|
26
|
+
- `walletFilter` - A filter function that accepts a wallet and returns a boolean. This filters the
|
|
27
|
+
list of wallets presented to users when selecting a wallet to connect from, ensuring that only
|
|
28
|
+
wallets that meet the dApp requirements can connect.
|
|
29
|
+
- `enableUnsafeBurner` - Enables the development-only unsafe burner wallet, useful for testing.
|
|
30
|
+
- `autoConnect` - Enables automatically reconnecting to the most recently used wallet account upon
|
|
31
|
+
mounting.
|
|
32
|
+
- `slushWallet` - Enables and configures the Slush wallet. Read more about how to
|
|
33
|
+
[use the Slush integration](./slush).
|
|
34
|
+
- `storage` - Configures how the most recently connected-to wallet account is stored. Set to `null`
|
|
35
|
+
to disable persisting state entirely. Defaults to using `localStorage` if it is available.
|
|
36
|
+
- `storageKey` - The key to use to store the most recently connected wallet account.
|
|
37
|
+
- `theme` - The theme to use for styling UI components. Defaults to using the light theme.
|