Skip to main content
Glama

Alchemy MCP Server

Official
convertHexBalanceToDecimal.ts1.42 kB
export default function convertHexBalanceToDecimal(response: any) { // Handle nested data structure - API returns { data: { data: { tokens: [...] } } } const responseData = response.data && response.data.data ? response.data.data : response.data; // Process tokens if they exist // LLMs are very bad at arithmetic, so we need to convert the hex balances to decimal if (responseData.tokens && Array.isArray(responseData.tokens)) { // Convert hex balances to decimal responseData.tokens = responseData.tokens.map((token: any) => { try { const processedToken = { ...token }; const hexTokenBalance = token.tokenBalance; const tokenDecimals = parseInt(token.tokenMetadata.decimals || '18', 10); const bigIntBalance = BigInt(hexTokenBalance); const decimalBalance = Number(bigIntBalance) / Math.pow(10, tokenDecimals); // Store both formats processedToken.originalHexBalance = hexTokenBalance; processedToken.tokenBalance = decimalBalance; return processedToken; } catch (error) { // On error, return token with balance as 0 but keep original hex return { ...token, originalHexBalance: token.tokenBalance, tokenBalance: 0 }; } }); } return responseData; }

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/alchemyplatform/alchemy-mcp-server'

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