Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

convert_formatted_to_wei

Convert human-readable cryptocurrency amounts to wei units for blockchain transactions. Specify token decimals to ensure accurate conversions in DeFi trading operations.

Instructions

Convert formatted amounts to wei using ethers.js

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesFormatted amount (e.g., '1.5' for 1.5 ETH)
decimalsYesNumber of decimal places for the token (e.g., 18 for ETH, 6 for USDC)

Implementation Reference

  • The main handler function that implements the convert_formatted_to_wei tool logic using ethers.parseUnits to convert formatted amounts to wei.
    async convertFormattedToWei(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 formatted amount to wei (BigNumber) const weiAmount = ethers.parseUnits(amount.toString(), decimals); return { message: "Formatted to wei conversion completed successfully", data: { originalAmount: amount.toString(), decimals: decimals, weiAmount: weiAmount.toString(), unit: decimals === 18 ? "ETH" : `${decimals} decimals`, }, summary: `Converted ${amount} (${decimals} decimals) to ${weiAmount.toString()} wei`, }; } catch (error) { throw new Error(`Formatted to wei conversion failed: ${error.message}`); } }
  • MCP tool schema definition including inputSchema, properties for amount and decimals, and required fields.
    name: TOOL_NAMES.CONVERT_FORMATTED_TO_WEI, description: "Convert formatted amounts to wei using ethers.js", inputSchema: { type: "object", properties: { amount: { type: "string", description: "Formatted amount (e.g., '1.5' for 1.5 ETH)", }, 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:1178-1180 (registration)
    Tool registration and dispatch in the CallToolRequestSchema handler switch statement, calling toolService.convertFormattedToWei.
    case TOOL_NAMES.CONVERT_FORMATTED_TO_WEI: result = await toolService.convertFormattedToWei(args); break;
  • Constant definition for the tool name used in registration and dispatch.
    CONVERT_FORMATTED_TO_WEI: "convert_formatted_to_wei",

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