Method Signature
align.blockchain.tokens.formatAmount(
amount: string,
decimals: number
): string
Parameters
Raw amount in smallest units (e.g., wei, satoshi)
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
const formatted = align.blockchain.tokens.formatAmount("1000000", 6);
console.log(formatted, "USDC"); // 1.00 USDC
Common Token Decimals
| Token | Decimals |
|---|
| USDC | 6 |
| USDT | 6 |
| ETH/MATIC | 18 |
| WBTC | 8 |
Use parseAmount() for the reverse operation (human-readable → raw).