Skip to content
Docs
Hooks
useAccount

useAccount

Hook for accessing account data and connection status.

import { useAccount } from 'wagmi'

Usage

import { useAccount } from 'wagmi'

function App() {
  const { address, isConnecting, isDisconnected } = useAccount()

  if (isConnecting) return <div>Connecting…</div>
  if (isDisconnected) return <div>Disconnected</div>
  return <div>{address}</div>
}

Return Value

{
  address?: string
  connector?: Connector
  isConnecting: boolean
  isReconnecting: boolean
  isConnected: boolean
  isDisconnected: boolean
  status: 'connecting' | 'reconnecting' | 'connected' | 'disconnected'
}

Configuration

onConnect (optional)

Function to invoke when account connects.

It provides the connected address & connector, as well as a isReconnected flag for if the user reconnected via autoConnect.

import { useAccount } from 'wagmi'

function App() {
  const account = useAccount({
    onConnect({ address, connector, isReconnected }) {
      console.log('Connected', { address, connector, isReconnected })
    },
  })
}

onDisconnect (optional)

Function to invoke when account disconnects.

import { useAccount } from 'wagmi'

function App() {
  const account = useAccount({
    onDisconnect() {
      console.log('Disconnected')
    },
  })
}