get-registration-price
Calculate the cost to register an ENS name by specifying the desired name and registration duration in years through the ENS MCP Server.
Instructions
Get the price to register an ENS name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration | No | Registration duration in years | |
| name | Yes | The ENS name to check price for (without .eth suffix) |
Implementation Reference
- utils/index.ts:378-408 (handler)The handler function that implements the core logic for getting the ENS registration price. Normalizes the name, calculates duration in seconds, fetches price via publicClient.getPrice, formats using ethers.formatEther, and handles errors.export async function getRegistrationPrice( { name, duration = 1 }: { name: string, duration?: number }): Promise<ServerResponse> { const normalizedName = normalizeName(name); try { const durationInSeconds = duration * 365 * 24 * 60 * 60; const price = await publicClient.getPrice({ nameOrNames: normalizedName, duration: durationInSeconds }); return { content: [{ type: "text", text: `Registration price for ${normalizedName} for ${duration} year(s):\n` + `- Base Price: ${ethers.formatEther(price.base)} ETH\n` + `- Premium: ${ethers.formatEther(price.premium)} ETH\n` + `- Total: ${ethers.formatEther(price.base + price.premium)} ETH` }], isError: false }; } catch (error) { const errorMessage = handleEnsError(error, "get registration price"); return { content: [{ type: "text", text: errorMessage }], isError: true }; } }
- index.ts:99-107 (registration)MCP server tool registration for 'get-registration-price', including description, Zod input schema, and reference to the handler function.server.tool( "get-registration-price", "Get the price to register an ENS name", { name: z.string().describe("The ENS name to check price for (without .eth suffix)"), duration: z.number().int().min(1).describe("Registration duration in years").default(1) , }, async (params) => getRegistrationPrice( params) );
- index.ts:102-105 (schema)Zod schema defining input parameters: name (string) and duration (number, default 1, min 1).{ name: z.string().describe("The ENS name to check price for (without .eth suffix)"), duration: z.number().int().min(1).describe("Registration duration in years").default(1) , },
- clients/index.ts:47-50 (helper)ENS public client configuration used by the handler to call getPrice method.export const publicClient: EnsPublicClient = createEnsPublicClient({ chain: mainnet, transport: configureTransport() });