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