get-ens-name
Retrieve the ENS name associated with an Ethereum address to identify wallet owners and simplify blockchain interactions.
Instructions
Get the ENS name for an Ethereum address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Ethereum address (0x format) |
Implementation Reference
- src/server.ts:263-279 (handler)Handler for 'get-ens-name' tool: parses input using AddressSchema, calls etherscanService.getENSName(address), formats response.
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:135-149 (registration)Tool registration in listTools response, including name, description, and inputSchema.
{ 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"], }, }, - src/server.ts:33-35 (schema)Zod schema for validating Ethereum address input, used in get-ens-name handler.
const AddressSchema = z.object({ address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address format'), }); - EtherscanService.getENSName method: core logic using ethers.provider.lookupAddress to resolve ENS name from address.
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; } }