Wallet Kit
API
useWalletKit

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 to null if 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 to null if 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 be DISCONNECTED, CONNECTING, CONNECTED, or ERROR.

Additionally, there are three booleans for convenience that are derived from the status field

  • isConnecting - If the status is CONNECTING
  • isConnected - If the status is CONNECTED
  • isError - If the status is ERROR

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 wallet
  • signMessage(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.