Skip to content

getAccount

Action for getting current account.

Import

ts
import { getAccount } from '@wagmi/core'
import { getAccount } from '@wagmi/core'

Usage

ts
import { getAccount } from '@wagmi/core'
import { config } from './config'

const account = getAccount(config)
import { getAccount } from '@wagmi/core'
import { config } from './config'

const account = getAccount(config)
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

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

Return Type

ts
import { type GetAccountReturnType } from '@wagmi/core'
import { type GetAccountReturnType } from '@wagmi/core'

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"; }
}

Released under the MIT License.