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 Values

{
  data?: {
    address: string
    connector: Connector
  }
  error?: Error
  isError boolean
  isFetching: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  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)
    },
  })
}