The getNames utility is designed to retrieve multiple names from an onchain identity provider for an array of addresses in a single batch request. Consider the utility instead of the hook when you use it with Next.js or any Node.js backend.

Usage

Get ENS names from multiple addresses:
import { getNames } from '@coinbase/onchainkit/identity';

const addresses = [
'0x4bEf0221d6F7Dd0C969fe46a4e9b339a84F52FDF',
'0x838aD0EAE54F99F1926dA7C3b6bFbF617389B4D9'
];
const names = await getNames({ addresses });

Get Basenames from multiple addresses:
import { getNames } from '@coinbase/onchainkit/identity';
import { base } from 'viem/chains';

const addresses = [
'0x4bEf0221d6F7Dd0C969fe46a4e9b339a84F52FDF',
'0x4bEf0221d6F7Dd0C969fe46a4e9b339a84F52FDF'
];
const names = await getNames({ addresses, chain: base });

Get a mix of ENS names and sliced addresses when some addresses don’t have names:
import { getNames } from '@coinbase/onchainkit/identity';

const addresses = [
'0x4bEf0221d6F7Dd0C969fe46a4e9b339a84F52FDF',
'0x1234567890abcdef1234567890abcdef12345678'
];
const names = await getNames({ addresses });

Returns

Promise<GetNameReturnType[]>

type GetNameReturnType = string | Basename | null;

type Basename = BaseMainnetName | BaseSepoliaName;
type BaseMainnetName = `${string}.base.eth`;
type BaseSepoliaName = `${string}.basetest.eth`;

Parameters

type GetNamesParams = {
  /** Array of Ethereum addresses to resolve names for */
  addresses: Address[];
  /** Optional chain for domain resolution */
  chain?: Chain;
};

type Address = `0x${string}`;

type Chain = {
  id: number;
  name: string;
  // ... other chain properties
};