get-ens-name
Resolve Ethereum addresses to their ENS names using Etherscan's API. Input an address in 0x format to retrieve the associated ENS domain name.
Instructions
Get the ENS name for an Ethereum address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Ethereum address (0x format) |
Implementation Reference
- src/server.ts:301-319 (handler)Executes the 'get-ens-name' tool by validating the input address with AddressSchema, calling EtherscanService.getENSName, and formatting the response as text.if (name === "get-ens-name") { try { const { address } = AddressSchema.parse(args); const ensName = await etherscanService.getENSName(address); const response = ensName ? `ENS name for ${address}: ${ensName}` : `No ENS name found for ${address}`; return { content: [{ type: "text", text: response }], }; } catch (error) { if (error instanceof z.ZodError) { throw new Error( `Invalid input: ${error.errors.map((e) => e.message).join(", ")}` ); } throw error; } }
- src/server.ts:36-40 (schema)Zod schema used to validate the 'address' input parameter for the get-ens-name tool (and others).const AddressSchema = z.object({ address: z .string() .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format"), });
- src/server.ts:146-160 (registration)Registers the 'get-ens-name' tool in the ListTools response, including its description and input schema.{ name: "get-ens-name", description: "Get the ENS name for an Ethereum address", inputSchema: { type: "object", properties: { address: { type: "string", description: "Ethereum address (0x format)", pattern: "^0x[a-fA-F0-9]{40}$", }, }, required: ["address"], }, },
- Core implementation that resolves the Ethereum address to its ENS name using ethers.EtherscanProvider.lookupAddress.async getENSName(address: string): Promise<string | null> { try { const validAddress = ethers.getAddress(address); return await this.provider.lookupAddress(validAddress); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get ENS name: ${error.message}`); } throw error; } }