Skip to content

useAccount

Hook for getting current account.

Import

ts
import { useAccount } from 'wagmi'

Usage

tsx
import { useAccount } from 'wagmi'

function App() {
  const account = useAccount()
}
ts
import { http, createConfig } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type UseAccountParameters } from 'wagmi'

config

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

tsx
import { useAccount } from 'wagmi'
import { config } from './config'

function App() {
  const account = useAccount({
    config,
  })
}
ts
import { http, createConfig } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Return Type

ts
import { type UseAccountReturnType } from 'wagmi'

address

Address | undefined

  • Connected address from connector.
  • Defaults to first address in addresses.

addresses

readonly Address[] | undefined

Connected addresses from connector.

chain

Chain | undefined

Connected chain from connector. If chain is not configured by config, it will be undefined.

chainId

number | undefined

Connected chain id from connector.

connector

Connector | undefined

Connected connector.

isConnecting / isReconnecting / isConnected / isDisconnected

boolean

Boolean variables derived from status.

status

'connecting' | 'reconnecting' | 'connected' | 'disconnected'

  • 'connecting' attempting to establish connection.
  • 'reconnecting' attempting to re-establish connection to one or more connectors.
  • 'connected' at least one connector is connected.
  • 'disconnected' no connection to any connector.

You can use status to narrow the return type.

For example, when status is 'connected' properties like address are guaranteed to be defined.

ts
if (
account
.
status
=== 'connected') {
account
}

Or when status is 'disconnected' properties like address are guaranteed to be undefined:

ts
if (
account
.
status
=== 'disconnected') {
account
}

Action

Released under the MIT License.