Skip to content

useAccount

Hook for getting current account.

Import

ts
import { useAccount } from 'wagmi'
import { useAccount } from 'wagmi'

Usage

tsx
import { useAccount } from 'wagmi'

function App() {
  const account = useAccount()
}
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(),
  },
})
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'
import { type UseAccountParameters } from 'wagmi'

config

Config | undefined

Config to use instead of retrieving from the from nearest WagmiProvider.

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

function App() {
  const account = useAccount({
    config, 
  })
}
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(),
  },
})
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'
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
ts
if (account.status === 'connected') {
account
const account: { address: `0x${string}`; addresses: readonly [`0x${string}`, ...`0x${string}`[]]; chain: Chain | undefined; chainId: number; connector: Connector; isConnected: true; isConnecting: false; isDisconnected: false; isReconnecting: false; status: "connected"; }
}
ts
if (account.status === 'connected') {
account
const account: { address: `0x${string}`; addresses: readonly [`0x${string}`, ...`0x${string}`[]]; chain: Chain | undefined; chainId: number; connector: Connector; isConnected: true; isConnecting: false; isDisconnected: false; isReconnecting: false; status: "connected"; }
}

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

ts
ts
if (account.status === 'disconnected') {
account
const account: { address: undefined; addresses: undefined; chain: undefined; chainId: undefined; connector: undefined; isConnected: false; isReconnecting: false; isConnecting: false; isDisconnected: true; status: "disconnected"; }
}
ts
if (account.status === 'disconnected') {
account
const account: { address: undefined; addresses: undefined; chain: undefined; chainId: undefined; connector: undefined; isConnected: false; isReconnecting: false; isConnecting: false; isDisconnected: true; status: "disconnected"; }
}

Action

Released under the MIT License.