The useName hook is used to get name from an onchain identity provider for a given address. It is implemented with useQuery from @tanstack/react-query, and returns a UseQueryResult object, allowing you to pass through all @tanstack/react-query options.

Usage

Get ENS name from an address:
import { useName } from '@coinbase/onchainkit/identity';

const address = '0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1';
const { data: name, isLoading } = await useName({ address });

Get Basename from an address:
import { useName } from '@coinbase/onchainkit/identity';
import { base } from 'viem/chains';

const address = '0x02feeb0AdE57b6adEEdE5A4EEea6Cf8c21BeB6B1';
const { data: name, isLoading } = await useName({ address, chain: base });

Returns

useQuery<Promise<GetNameReturnType>>

type GetNameReturnType = string | Basename | null;

Parameters

UseNameParams

type UseNameParams = {
  /** The address for which the ENS or Basename is to be fetched. */
  address?: Address;
  /** Optional chain for domain resolution */
  chain?: Chain;
};

UseQueryOptions

type UseQueryOptions<TData = unknown> = Omit<
  TanstackUseQueryOptions<TData>,
  'queryKey' | 'queryFn'
>;