Core TypeScript library for ENS contract naming. This library provides the fundamental functionality for naming smart contracts with ENS (Ethereum Name Service), handling subname creation, forward and reverse resolution, and supporting both L1 and L2 networks.
npm install @enscribe/enscribe
# or
pnpm add @enscribe/enscribe
# or
yarn add @enscribe/enscribeimport { nameContract } from "@enscribe/enscribe";
import { createWalletClient, http } from "viem";
import { sepolia } from "viem/chains";
// Create a wallet client
const walletClient = createWalletClient({
chain: sepolia,
transport: http(),
account: "0x...", // your account address
});
// Name a contract - the library handles all network configuration internally
const result = await nameContract({
name: "mycontract.myname.eth",
contractAddress: "0x1234567890123456789012345678901234567890",
walletClient,
chainName: "sepolia", // Library determines contracts and network logic
enableMetrics: true, // Optional: enable metrics logging
});
console.log(`Contract named successfully!`);
console.log(`Explorer URL: ${result.explorerUrl}`);
console.log(`Contract Type: ${result.contractType}`);
console.log(`Transactions:`, result.transactions);import { nameContract } from "@enscribe/enscribe";
import { createWalletClient, http } from "viem";
import { optimismSepolia } from "viem/chains";
// Create L2 wallet client
const l2WalletClient = createWalletClient({
chain: optimismSepolia,
transport: http(),
account: "0x...",
});
// Name a contract on L2 - library handles all network logic
const result = await nameContract({
name: "mycontract.myname.eth",
contractAddress: "0x1234567890123456789012345678901234567890",
walletClient: l2WalletClient, // L2 wallet client
chainName: "optimism-sepolia", // Library determines L1/L2 setup
enableMetrics: true,
});The main function to name a contract with ENS.
- name (
string): The normalized ENS name to assign to the contract - contractAddress (
string): The address of the contract to name - walletClient (
WalletClient): Viem wallet client for transactions - chainName (
string): Network name (e.g., "sepolia", "optimism-sepolia", "base", etc.) - l2WalletClient (
WalletClient | null, optional): Additional L2 wallet client if needed - correlationId (
string, optional): Correlation ID for metrics tracking - opType (
string, optional): Operation type for metrics - enableMetrics (
boolean, optional): Enable metrics logging (default: false)
A NameContractResult object containing:
- success (
boolean): Whether the operation succeeded - name (
string): The normalized name that was set - contractAddress (
string): The contract address that was named - transactions (
object): Transaction hashes for each operationsubname: Subname creation transactionforwardResolution: Forward resolution transactionreverseResolution: Reverse resolution transactionl2ForwardResolution: L2 forward resolution transaction (if applicable)l2ReverseResolution: L2 reverse resolution transaction (if applicable)
- contractType (
"Ownable" | "ReverseClaimer" | "Unknown"): Detected contract type - explorerUrl (
string): ENScribe explorer URL for the named contract
Check if a contract implements the Ownable interface.
isReverseClaimable(address: string, walletClient: WalletClient, ensRegistry: string): Promise<boolean>
Check if a contract implements ReverseClaimer.
Check if the wallet is the owner of the contract.
Parse a normalized ENS name into label and parent components.
Validate an Ethereum address.
Get ENS contract addresses for a specific network.
Supported Networks:
- Mainnet:
"mainnet" - Testnets:
"sepolia" - L2 Mainnets:
"linea","base","optimism","arbitrum","scroll" - L2 Testnets:
"linea-sepolia","base-sepolia","optimism-sepolia","arbitrum-sepolia","scroll-sepolia" - Local:
"localhost"
Example:
import { getContractAddresses } from "@enscribe/enscribe";
const contracts = getContractAddresses("sepolia");
console.log(contracts.ENS_REGISTRY); // "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"Get the network name from a chain ID.
Example:
import { getNetworkNameFromChainId } from "@enscribe/enscribe";
const networkName = getNetworkNameFromChainId(11155111); // "sepolia"Validate that contract addresses are properly formatted.
A constant object containing all pre-configured ENS contract addresses for supported networks.
The library exports the following TypeScript types:
ENSContracts: ENS contract addresses configurationNameContractOptions: Options for thenameContractfunctionNameContractResult: Result from naming a contractContractType: Type of contract detected
This library supports naming the following contract types:
- Ownable Contracts: Contracts that implement the Ownable pattern with an
owner()function - ReverseClaimer Contracts: Contracts that have claimed their reverse ENS record
- Node.js >= 18.0.0
- viem >= 2.0.0
MIT