Documentation
/Hooks
/useAccount
useAccount
Hook for accessing the connected account.
import { useAccount } from 'wagmi'
Usage
import { useAccount } from 'wagmi'
const App = () => {
const [{ data, error, loading }, disconnect] = useAccount()
return (
<>
<div>{data?.address}</div>
<button onClick={disconnect}>
Disconnect from {data?.connector?.name}
</button>
</>
)
}
Return Values
result
{
data?: {
address: string
connector: Connector
ens?: {
avatar?: string
name: string
}
}
error?: Error
loading?: boolean
}
disconnect
() => void
Configuration
fetchEns (optional)
Fetches ENS name and avatar for connected account. Defaults to false
.
import { useAccount } from 'wagmi'
const App = () => {
const [{ data, error, loading }] = useAccount({
fetchEns: true,
})
if (loading) return <div>Fetching ENS…</div>
if (error) return <div>Error fetching ENS</div>
return (
<>
<div>{data?.ens?.name}</div>
<img src={data?.ens?.avatar} />
</>
)
}