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
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount in wei (as string to handle large numbers) | |
| decimals | Yes | Number 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
- src/toolService.js:749-777 (handler)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}`); } }
- src/index.js:933-952 (schema)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;
- src/constants.js:44-44 (helper)Constant definition for the tool name used throughout the codebase.CONVERT_WEI_TO_FORMATTED: "convert_wei_to_formatted",