Skip to content

useEvmAddress()

Use it to fetch the connected account EVM address.

INFO

Unlike useAccountId, this hook can retrieve the EVM address of the connected wallet, whether it's a native or EVM-compatible wallet.

Usage

When parameter multiSession={false}:

tsx
import { useEvmAddress } from '@buidlerlabs/hashgraph-react-wallets'

const App = () => {
  const { data: evmAddress } = useEvmAddress()

  return <span>{evmAddress ?? '-'}</span>
}

Parameters

ts
interface IUseEvmAddressProps<Connector> {
  connector?: Connector | null
  autoFetch?: boolean
}

- connector

  • Type: HWBridgeConnector
  • Required: false

Request the EVM address for a specific wallet when multiSession={true}

tsx
import { HashpackConnector } from '@buidlerlabs/hashgraph-react-wallets/connectors'
import { useEvmAddress } from '@buidlerlabs/hashgraph-react-wallets'

const App = () => {
  const { data: evmAddress } = useEvmAddress({ connector: HashpackConnector }) 

  return <span>{evmAddress ?? '-'}</span>
}

- autoFetch

  • Type: boolean
  • Required: false
tsx
import { useWallet, useEvmAddress } from '@buidlerlabs/hashgraph-react-wallets'

const App = () => {
  const { isConnected } = useWallet() 
  const { data: evmAddress } = useEvmAddress({ autoFetch: isConnected }) 

  return <span>{evmAddress ?? '-'}</span>
}

Return Type

Returns a TanStack query result where TData is a string

ts
type UseQueryResult<string | null, Error>