UNPKG

@justaname.id/hybrid-primary-name

Version:

**Hybrid Primary Name** is a Viem extension package that enables reverse ENS resolution to fetch the primary ENS name associated with a given Ethereum address. It integrates seamlessly with both Viem's `createPublicClient` and ENS's `createEnsPublicClient

29 lines (28 loc) 1.15 kB
import { ClientWithEns } from "@ensdomains/ensjs/dist/types/contracts/consts"; import { Address } from "viem"; /** * Creates a plugin that extends the PublicClient with ENS resolution capabilities. * This plugin adds the ability to perform reverse ENS lookups using both on-chain * and API-based resolution methods. * * @returns A function that extends the client with the getEnsFromAddress method */ export declare function primaryName(): (client: ClientWithEns) => { /** * Performs reverse ENS resolution for a given Ethereum address. * First attempts on-chain resolution, then falls back to API-based lookup. * * @param address - The Ethereum address to resolve * @returns The primary ENS name associated with the address, or null if none found * @throws Error if the current chain ID is not supported (must be mainnet or sepolia) * * @example * ```typescript * const ensName = await client.getEnsFromAddress('0x123...') * if (ensName) { * console.log(`ENS name: ${ensName}`) * } * ``` */ getEnsFromAddress(address: Address): Promise<string | null>; };