const API = process.env.FREEDOM_API ?? "https://api-v1.freedom.st"; export async function getChainInfo(): Promise> { const res = await fetch(`${API}/rpc/info`); return res.json(); } export async function getExchangeRates(): Promise> { const res = await fetch(`${API}/invoice/rates`); return res.json(); } export async function getAddressInfo(address: string): Promise { const res = await fetch(`${API}/address/${address}`); return res.json(); } export async function getAddressInfoBulk(addresses: string[]): Promise> { if (addresses.length === 0) return {}; const res = await fetch(`${API}/address`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ terms: addresses }), }); return res.json(); } export function getQrUrl(text: string): string { return `${API}/invoice/qr/${encodeURIComponent(text)}`; } export async function getAvailableCoins(): Promise { const info = await getChainInfo(); return Object.entries(info) .filter(([_, v]) => v && v.uptime != null) .map(([k]) => k); }