Skip to content

useAccount

The useAccount hook provides a convenient way to access the current wallet account information and connection status. It combines data from the wallet adapter and chain configuration to give you a unified interface for working with the connected account.

Usage

import React from 'react'
import { useAccount } from '@razorlabs/razorkit';
 
function AccountInfo() {
  const { 
    address, 
    isConnected, 
    isConnecting, 
    chain 
  } = useAccount();
  
  if (isConnecting) {
    return <div>Connecting...</div>;
  }
  
  if (!isConnected) {
    return <div>Not connected</div>;
  }
  
  return (
    <div>
      <h2>Account Information</h2>
      <p>Address: {address}</p>
      <p>Network: {chain?.name}</p>
    </div>
  );
}

Return Value

The useAccount hook returns an object with the following properties:

PropertyTypeDescription
addressstring | undefinedThe address of the currently connected account
addressesstring[]Array of all account addresses available in the wallet
chainChain | undefinedThe current chain configuration
chainIdstring | undefinedThe ID of the current chain
connectorWalletAdapter | undefinedThe current wallet adapter instance
status"connected" | "connecting" | "disconnected" | "error"The current connection status
isConnectedbooleanWhether the wallet is currently connected
isConnectingbooleanWhether the wallet is currently connecting
isDisconnectedbooleanWhether the wallet is currently disconnected
reconnectingbooleanWhether the wallet is currently reconnecting

Implementation Details

The useAccount hook combines data from two other hooks:

  • useWallet - Provides wallet connection state and methods
  • useChain - Provides information about the current blockchain network

It also computes derived state like isConnected, isConnecting, and isDisconnected for convenience.

Related Hooks

  • useWallet - Access the wallet adapter directly
  • useChain - Access the current chain configuration