Skip to main content
Glama
buildwithgrove

Grove's MCP Server for Pocket Network

convert_units

Convert cryptocurrency values between wei, gwei, and eth units for accurate blockchain calculations and transaction analysis.

Instructions

Convert between wei, gwei, and eth units

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromUnitYesSource unit
toUnitYesTarget unit
valueYesValue to convert

Implementation Reference

  • Handler logic in handleUtilityTool that processes convert_units arguments and delegates to the service's convertUnits method, returning formatted response.
    case 'convert_units': { const value = args?.value as string; const fromUnit = args?.fromUnit as 'wei' | 'gwei' | 'eth'; const toUnit = args?.toUnit as 'wei' | 'gwei' | 'eth'; const result = advancedBlockchain.convertUnits(value, fromUnit, toUnit); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; }
  • Input schema defining parameters for the convert_units tool: value (string), fromUnit and toUnit (enum: wei, gwei, eth).
    inputSchema: { type: 'object', properties: { value: { type: 'string', description: 'Value to convert', }, fromUnit: { type: 'string', enum: ['wei', 'gwei', 'eth'], description: 'Source unit', }, toUnit: { type: 'string', enum: ['wei', 'gwei', 'eth'], description: 'Target unit', }, }, required: ['value', 'fromUnit', 'toUnit'], },
  • Tool registration object in registerUtilityHandlers function, including name, description, and schema.
    { name: 'convert_units', description: 'Convert between wei, gwei, and eth units', inputSchema: { type: 'object', properties: { value: { type: 'string', description: 'Value to convert', }, fromUnit: { type: 'string', enum: ['wei', 'gwei', 'eth'], description: 'Source unit', }, toUnit: { type: 'string', enum: ['wei', 'gwei', 'eth'], description: 'Target unit', }, }, required: ['value', 'fromUnit', 'toUnit'], }, },
  • AdvancedBlockchainService.convertUnits method implementing the core unit conversion logic using BigInt and predefined unit multipliers.
    convertUnits( value: string, fromUnit: 'wei' | 'gwei' | 'eth', toUnit: 'wei' | 'gwei' | 'eth' ): EndpointResponse { try { const unitMap = { wei: 1n, gwei: 1000000000n, eth: 1000000000000000000n, }; const valueWei = BigInt(value) * unitMap[fromUnit]; const result = valueWei / unitMap[toUnit]; return { success: true, data: { value: result.toString(), fromUnit, toUnit, exact: valueWei % unitMap[toUnit] === 0n, }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to convert units', }; } }

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/buildwithgrove/mcp-pocket'

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