useWallet
Connect and manage the user's Solana wallet.
Import
import { useWallet } from '@wankmi/wankmi'Usage
import { useWallet } from '@wankmi/wankmi'
function ConnectButton() {
const { connect, disconnect, connected, publicKey, connecting } = useWallet()
if (connecting) return <button disabled>Connecting...</button>
if (connected) {
return (
<div>
<p>{publicKey?.toBase58()}</p>
<button onClick={disconnect}>Disconnect</button>
</div>
)
}
return <button onClick={connect}>Connect</button>
}Return Value
| Property | Type | Description |
|---|---|---|
connect | () => Promise<void> | Prompt the user to connect their wallet |
disconnect | () => Promise<void> | Disconnect the active wallet |
connected | boolean | Whether a wallet is currently connected |
connecting | boolean | Whether a connection attempt is in progress |
publicKey | PublicKey | null | The connected wallet's public key |
wallet | WalletAdapter | null | The active wallet adapter instance |
Notes
💡
useWallet must be used inside a WankmiProvider. Calling it outside the provider will throw.
connect()will open the wallet's browser extension UI (e.g. Phantom popup). The user must approve the connection.publicKeyisnullwhen disconnected.- The adapter used is determined by which wallet the user has installed. If multiple adapters are configured, the first detected wallet is used.