Skip to content
Docs
/
Hooks
/
useAccount

useAccount

Hook for accessing the connected account.

import { useAccount } from 'wagmi'

Usage

import { useAccount } from 'wagmi'

function App() {
  const { data, isError, isLoading } = useAccount()

  if (isLoading) return <div>Loading account…</div>
  if (isError) return <div>Error loading account</div>
  return <div>{data?.address}</div>
}

Return Value

{
  data?: {
    address: string
    connector: Connector
  }
  error?: Error
  isIdle: boolean
  isLoading: boolean
  isFetching: boolean
  isSuccess: boolean
  isError: boolean
  isFetched: boolean
  isRefetching: boolean
  refetch: (options: {
    throwOnError: boolean
    cancelRefetch: boolean
  }) => Promise<{
    address: string
    connector: Connector
  }>
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

suspense (optional)

Set this to true to enable suspense mode.

import { useAccount } from 'wagmi'

function App() {
  const account = useAccount({
    suspense: true,
  })
}

onError (optional)

Function to invoke when an error is thrown while fetching new data.

import { useAccount } from 'wagmi'

function App() {
  const account = useAccount({
    onError(error) {
      console.log('Error', error)
    },
  })
}

onSettled (optional)

Function to invoke when fetching is settled (either successfully fetched, or an error has thrown).

import { useAccount } from 'wagmi'

function App() {
  const account = useAccount({
    onSettled(data, error) {
      console.log('Settled', { data, error })
    },
  })
}

onSuccess (optional)

Function to invoke when fetching new data is successful.

import { useAccount } from 'wagmi'

function App() {
  const account = useAccount({
    onSuccess(data) {
      console.log('Success', data)
    },
  })
}