Skip to main content
Glama

formatUnits

Convert blockchain value to readable units using specified decimals or unit names for clearer Ethereum network interactions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
unitYesThe number of decimals or unit name (e.g., 'gwei', 18)
valueYesThe value to format

Implementation Reference

  • 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)}` }] }; } }
  • 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)" ) },
  • Registration of the formatUnits tool on the MCP server using server.tool with name, schema, and handler.
    server.tool( "formatUnits",

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/crazyrabbitLTC/mcp-ethers-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server