Skip to main content
Glama

DeFi Trading Agent MCP Server

by edkdev

convert_wei_to_formatted

Convert wei amounts to human-readable formats by specifying token decimals, enabling clear crypto transaction value representation for trading agents.

Instructions

Convert wei amounts to human-readable format using ethers.js

Input Schema

NameRequiredDescriptionDefault
amountYesAmount in wei (as string to handle large numbers)
decimalsYesNumber of decimal places for the token (e.g., 18 for ETH, 6 for USDC)

Input Schema (JSON Schema)

{ "properties": { "amount": { "description": "Amount in wei (as string to handle large numbers)", "type": "string" }, "decimals": { "description": "Number of decimal places for the token (e.g., 18 for ETH, 6 for USDC)", "type": "integer" } }, "required": [ "amount", "decimals" ], "type": "object" }

Implementation Reference

  • The primary handler function that implements the tool logic: validates input, uses ethers.formatUnits to convert wei to human-readable format, and returns structured results.
    async convertWeiToFormatted(params) { const { amount, decimals } = params; if (!amount) { throw new Error("amount is required"); } if (decimals === undefined || decimals === null) { throw new Error("decimals is required"); } try { // Convert the amount to a BigNumber and format it const formattedAmount = ethers.formatUnits(amount.toString(), decimals); return { message: "Wei to formatted conversion completed successfully", data: { originalAmount: amount.toString(), decimals: decimals, formattedAmount: formattedAmount, unit: decimals === 18 ? "ETH" : `${decimals} decimals`, }, summary: `Converted ${amount} wei to ${formattedAmount} (${decimals} decimals)`, }; } catch (error) { throw new Error(`Wei to formatted conversion failed: ${error.message}`); } }
  • MCP tool schema definition including name, description, and input validation schema for 'convert_wei_to_formatted'.
    { name: TOOL_NAMES.CONVERT_WEI_TO_FORMATTED, description: "Convert wei amounts to human-readable format using ethers.js", inputSchema: { type: "object", properties: { amount: { type: "string", description: "Amount in wei (as string to handle large numbers)", }, decimals: { type: "integer", description: "Number of decimal places for the token (e.g., 18 for ETH, 6 for USDC)", }, }, required: ["amount", "decimals"], }, },
  • src/index.js:1174-1176 (registration)
    Registration in the CallToolRequestHandler switch statement that dispatches calls to the handler function.
    case TOOL_NAMES.CONVERT_WEI_TO_FORMATTED: result = await toolService.convertWeiToFormatted(args); break;
  • Constant definition for the tool name used throughout the codebase.
    CONVERT_WEI_TO_FORMATTED: "convert_wei_to_formatted",

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/edkdev/defi-trading-mcp'

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