formatEther
Convert wei values to ether for easy Ethereum transactions and balances. Simplify blockchain interactions by formatting cryptocurrency amounts accurately.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| wei | Yes | The wei value to format |
Implementation Reference
- src/tools/core.ts:279-306 (registration)Registration of the formatEther MCP tool, including schema and handler function.server.tool( "formatEther", { wei: z.string().describe( "The wei value to format" ) }, async ({ wei }) => { try { const etherValue = ethers.formatEther(wei); return { content: [{ type: "text", text: etherValue }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error formatting ether: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
- src/tools/core.ts:281-285 (schema)Zod input schema for formatEther tool: expects a 'wei' string parameter.{ wei: z.string().describe( "The wei value to format" ) },
- src/tools/core.ts:286-305 (handler)Handler function that formats the input wei value to ether using ethers.formatEther and returns the result in MCP content format, with error handling.async ({ wei }) => { try { const etherValue = ethers.formatEther(wei); return { content: [{ type: "text", text: etherValue }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error formatting ether: ${error instanceof Error ? error.message : String(error)}` }] }; } }