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 blockchain calculations and transaction analysis.

Instructions

Convert between wei, gwei, and eth units

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesValue to convert
fromUnitYesSource unit
toUnitYesTarget unit

Implementation Reference

  • Executes the convert_units tool: extracts arguments, calls AdvancedBlockchainService.convertUnits, formats response as MCP content with error flag.
    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 for convert_units tool defining value (string), fromUnit and toUnit (enum: wei/gwei/eth), all required.
    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 for convert_units returned by registerUtilityHandlers, included in server's tool list.
    { 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'], }, },
  • Core implementation of unit conversion: converts value from fromUnit to toUnit using BigInt, checks if exact, returns EndpointResponse.
    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