resolve_ens_name
Convert ENS domain names like 'vitalik.eth' into Ethereum wallet addresses using the EVM MCP Server's blockchain interface.
Instructions
Resolve an ENS name to an Ethereum address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ensName | Yes | ENS name to resolve (e.g., 'vitalik.eth') | |
| network | No | Network name or chain ID. ENS resolution works best on Ethereum mainnet. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:83-145 (registration)Tool registration, schema, and handler implementation for 'resolve_ens'. Validates input, normalizes ENS name, resolves address using services.resolveAddress, and returns formatted result or error.
server.tool( 'resolve_ens', 'Resolve an ENS name to an Ethereum address', { ensName: z.string().describe("ENS name to resolve (e.g., 'vitalik.eth')"), network: z .string() .optional() .describe( "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. ENS resolution works best on Ethereum mainnet. Defaults to Ethereum mainnet." ) }, async ({ ensName, network = 'ethereum' }) => { try { // Validate that the input is an ENS name if (!ensName.includes('.')) { return { content: [ { type: 'text', text: `Error: Input "${ensName}" is not a valid ENS name. ENS names must contain a dot (e.g., 'name.eth').` } ], isError: true }; } // Normalize the ENS name const normalizedEns = normalize(ensName); // Resolve the ENS name to an address const address = await services.resolveAddress(ensName, network); return { content: [ { type: 'text', text: JSON.stringify( { ensName: ensName, normalizedName: normalizedEns, resolvedAddress: address, network }, null, 2 ) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error resolving ENS name: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } ); - src/core/services/ens.ts:11-46 (helper)Core helper function resolveAddress that checks if input is address or ENS, normalizes ENS name, and uses viem publicClient.getEnsAddress to resolve to Ethereum address.
export async function resolveAddress( addressOrEns: string, network = 'ethereum' ): Promise<Address> { // If it's already a valid Ethereum address (0x followed by 40 hex chars), return it if (/^0x[a-fA-F0-9]{40}$/.test(addressOrEns)) { return addressOrEns as Address; } // If it looks like an ENS name (contains a dot), try to resolve it if (addressOrEns.includes('.')) { try { // Normalize the ENS name first const normalizedEns = normalize(addressOrEns); // Get the public client for the network const publicClient = getPublicClient(network); // Resolve the ENS name to an address const address = await publicClient.getEnsAddress({ name: normalizedEns, }); if (!address) { throw new Error(`ENS name ${addressOrEns} could not be resolved to an address`); } return address; } catch (error: any) { throw new Error(`Failed to resolve ENS name ${addressOrEns}: ${error.message}`); } } // If it's neither a valid address nor an ENS name, throw an error throw new Error(`Invalid address or ENS name: ${addressOrEns}`); } - src/server/server.ts:18-19 (registration)High-level registration of all EVM tools, including resolve_ens, via registerEVMTools.
registerEVMTools(server); registerEVMPrompts(server);