useWalletKit
The useWalletKit hook can be used to interact with wallets. This must be used in a component under
WalletKitProvider.
This hook automatically updates when any of the underlying state changes (for example, a new wallet is registered, or after a user connects to a wallet).
import { useWalletKit } from '@mysten/wallet-kit';
function AccountDisplay() {
const { currentAccount, currentWallet } = useWalletKit();
return (
<div>
{currentAccount}, {currentWallet.name}
</div>
);
}Wallet Kit Properties
wallets- A list of wallets that are currently detected and can be connected to.currentWallet- The currently connected wallet. Defaults tonullif there is no connected wallet.accounts- The list of accounts from the currently connected wallet. If no wallet is connected, this will be an empty array.currentAccount- The currently selected account, from the list of accounts from the currently connected wallet. This defaults tonullif a wallet is not connected. After a wallet is connected, this will default to the first account.status- The current state of the UI. Can either beDISCONNECTED,CONNECTING,CONNECTED, orERROR.
Additionally, there are three booleans for convenience that are derived from the status field
isConnecting- If the status isCONNECTINGisConnected- If the status isCONNECTEDisError- If the status isERROR
Wallet Kit Functions
In addition to the hook return’s properties, there are also functions that can be used to interact with the wallet:
connect(walletName: string)- Connect to a given wallet name.disconnect()- Disconnect from the currently connected walletsignMessage(messageInput)- Sign a message using the current account and wallet.signTransactionBlock(signTransactionInput)- Sign a transaction block using the current account and wallet.signAndExecuteTransactionBlock(signAndExecuteTransactionInput)- Sign a transaction block using the current account and wallet, and submit it to the chain for execution.