Skip to main content
Glama

Aptos Blockchain MCP

format.ts•2.99 kB
/** * Format utilities for Aptos MCP */ /** * Format APT amount from Octas to APT * @param octas Amount in Octas (smallest unit) * @returns Formatted APT amount */ export function formatAPT(octas: string | number | bigint): string { const octasNum = typeof octas === 'string' ? BigInt(octas) : BigInt(octas); const apt = Number(octasNum) / 100000000; // 1 APT = 10^8 Octas return apt.toFixed(8); } /** * Convert APT to Octas * @param apt Amount in APT * @returns Amount in Octas */ export function aptToOctas(apt: string | number): string { const aptNum = typeof apt === 'string' ? parseFloat(apt) : apt; return Math.floor(aptNum * 100000000).toString(); } /** * Format transaction hash for display * @param hash Transaction hash * @returns Formatted hash */ export function formatTxHash(hash: string): string { if (hash.length <= 16) return hash; return `${hash.slice(0, 8)}...${hash.slice(-8)}`; } /** * Format address for display * @param address Account address * @returns Formatted address */ export function formatAddress(address: string): string { if (address.length <= 16) return address; return `${address.slice(0, 8)}...${address.slice(-8)}`; } /** * Format coin amount with decimals * @param amount Amount in smallest unit * @param decimals Number of decimals * @returns Formatted amount */ export function formatCoinAmount(amount: string | number | bigint, decimals: number): string { const amountNum = typeof amount === 'string' ? BigInt(amount) : BigInt(amount); const divisor = BigInt(10 ** decimals); const wholePart = amountNum / divisor; const fractionalPart = amountNum % divisor; if (fractionalPart === 0n) { return wholePart.toString(); } const fractionalStr = fractionalPart.toString().padStart(decimals, '0'); const trimmedFractional = fractionalStr.replace(/0+$/, ''); return `${wholePart}.${trimmedFractional}`; } /** * Parse coin amount to smallest unit * @param amount Amount as string * @param decimals Number of decimals * @returns Amount in smallest unit */ export function parseCoinAmount(amount: string, decimals: number): string { const parts = amount.split('.'); const wholePart = parts[0] || '0'; const fractionalPart = (parts[1] || '').padEnd(decimals, '0').slice(0, decimals); const wholeNum = BigInt(wholePart); const fractionalNum = BigInt(fractionalPart); const multiplier = BigInt(10 ** decimals); return (wholeNum * multiplier + fractionalNum).toString(); } /** * Validate address format * @param address Address to validate * @returns True if valid */ export function isValidAddress(address: string): boolean { return /^0x[a-fA-F0-9]{1,64}$/.test(address); } /** * Normalize address to standard format * @param address Address to normalize * @returns Normalized address */ export function normalizeAddress(address: string): string { if (!address.startsWith('0x')) { address = '0x' + address; } return address.toLowerCase(); }

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/punkpeye/aptos-mcp'

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