Skip to content

useAccount

Composable for getting current account.

Import

ts
import { useAccount } from '@wagmi/vue'

Usage

vue
<script setup lang="ts">
import { 
useAccount
} from '@wagmi/vue'
const
account
=
useAccount
()
</script> <template> Address: {{
account
.
address
}}
</template>
ts
import { http, createConfig } from '@wagmi/vue'
import { mainnet, sepolia } from '@wagmi/vue/chains'

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

Parameters

ts
import { type 
UseAccountParameters
} from '@wagmi/vue'

config

Config | undefined

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

vue
<script setup lang="ts">
import { useAccount } from '@wagmi/vue'
import { config } from './config'

const account = useAccount({
  config, 
})
</script>
ts
import { http, createConfig } from '@wagmi/vue'
import { mainnet, sepolia } from '@wagmi/vue/chains'

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

Return Type

ts
import { type 
UseAccountReturnType
} from '@wagmi/vue'

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.