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
.
Install the package via npm or yarn:
npm install @justaname.id/hybrid-primary-name
# or
yarn add @justaname.id/hybrid-primary-name
import { createPublicClient, http } from 'viem';
import { addEnsContracts } from '@ensdomains/ensjs';
import { mainnet, sepolia } from 'viem/chains';
import { primaryName } from '@justaname.id/hybrid-primary-name';
const client = createPublicClient({
chain: addEnsContracts(**mainnet or sepolia**),
transport: http(**Provider URL**),
}).extend(primaryName())
import { http } from 'viem';
import { createEnsPublicClient } from '@ensdomains/ensjs'
import { mainnet, sepolia } from 'viem/chains';
import { primaryName } from '@justaname.id/hybrid-primary-name';
const client = createEnsPublicClient({
chain: **mainnet or sepolia**,
transport: http(**Provider URL**),
}).extend(primaryName())
The getEnsFromAddress
method returns the primary ENS name associated with the given Ethereum address.
await client.getEnsFromAddress(**Address**),