formatUnits
Convert blockchain value to readable units using specified decimals or unit names for clearer Ethereum network interactions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| unit | Yes | The number of decimals or unit name (e.g., 'gwei', 18) | |
| value | Yes | The value to format |
Implementation Reference
- src/tools/core.ts:349-368 (handler)The handler function for the formatUnits tool. It takes a value (string) and unit (string or number), formats the value using ethers.formatUnits, and returns the result as text content or an error response.async ({ value, unit }) => { try { const formattedValue = ethers.formatUnits(value, unit); return { content: [{ type: "text", text: formattedValue }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error formatting units: ${error instanceof Error ? error.message : String(error)}` }] }; } }
- src/tools/core.ts:342-348 (schema)Zod input schema for the formatUnits tool defining 'value' as string and 'unit' as string or number.value: z.string().describe( "The value to format" ), unit: z.union([z.string(), z.number()]).describe( "The number of decimals or unit name (e.g., 'gwei', 18)" ) },
- src/tools/core.ts:339-340 (registration)Registration of the formatUnits tool on the MCP server using server.tool with name, schema, and handler.server.tool( "formatUnits",