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
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | Value to convert | |
| fromUnit | Yes | Source unit | |
| toUnit | Yes | Target unit |
Implementation Reference
- src/handlers/utility-handlers.ts:88-104 (handler)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'], },
- src/handlers/utility-handlers.ts:15-38 (registration)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', }; } }