Skip to main content

Method Signature

align.blockchain.tokens.formatAmount(
  amount: string,
  decimals: number
): string

Parameters

amount
string
required
Raw amount in smallest units (e.g., wei, satoshi)
decimals
number
required
Token decimals (e.g., 6 for USDC, 18 for ETH)

Returns

Returns the formatted amount as a string (e.g., "100.50").

Examples

import Align from "@tolbel/align";

const align = new Align({
  apiKey: process.env.ALIGN_API_KEY!,
  environment: "sandbox",
});

// USDC has 6 decimals
// Raw: 100000000 = 100.00 USDC
const usdcAmount = align.blockchain.tokens.formatAmount("100000000", 6);
console.log(`${usdcAmount} USDC`); // 100.00 USDC

// ETH has 18 decimals
// Raw: 1500000000000000000 = 1.5 ETH
const ethAmount = align.blockchain.tokens.formatAmount(
  "1500000000000000000",
  18
);
console.log(`${ethAmount} ETH`); // 1.5 ETH

Common Token Decimals

TokenDecimals
USDC6
USDT6
ETH/MATIC18
WBTC8
Use parseAmount() for the reverse operation (human-readable → raw).