useCurrentWallet
The useCurrentWallet
hook retrieves the wallet that is currently connected to the dApp, if one
exists.
import { ConnectButton, useCurrentWallet } from '@mysten/dapp-kit';
function MyComponent() {
const { currentWallet, connectionStatus } = useCurrentWallet();
return (
<div>
<ConnectButton />
{connectionStatus === 'connected' ? (
<div>
<h2>Current wallet:</h2>
<div>Name: {currentWallet.name}</div>
<div>
Accounts:
<ul>
{currentWallet.accounts.map((account) => (
<li key={account.address}>- {account.address}</li>
))}
</ul>
</div>
</div>
) : (
<div>Connection status: {connectionStatus}</div>
)}
</div>
);
}
Example
Wallet properties
name
- The name of the walletversion
- The version of the wallet as a stringicon
- A data URL of the wallet icon as an SVGaccounts
- An array of accounts that are available in the walletfeatures
- An object with all the wallet-standard (opens in a new tab) features implemented by the walletchains
- An array of chain identifiers that the wallet supports
Connection status properties
-
connectionStatus
disconnected
- When no wallet connected to the dAppconnecting
- When a wallet connection attempt is in progressconnecting
- When a wallet is connected to the dApp
-
isDisconnected
- A derived boolean from the status variable above, provided for convenience. -
isConnecting
- A derived boolean from the status variable above, provided for convenience. -
isConnected
- A derived boolean from the status variable above, provided for convenience.