mega.balances()
Fetch token balances for the connected wallet. Optionally filter to a specific set of token addresses.
Signature
mega.balances(request: BalancesRequest): Promise<OwnedTokenResponse[]>
Parameters
Field
Type
Required
Notes
tokens
string[]
optional
Filter to specific contract addresses. Omit to return all wallet tokens.
Example
const balances = await mega.balances({
tokens: ['0xTokenA', '0xTokenB'],
});
console.log(balances);Response
type OwnedTokenResponse = {
name: string;
symbol: string;
decimals: number;
address: string;
balance: string; // raw integer string
displayBalance: string; // human-readable, decimals applied
image?: string;
usdPrice?: string;
usdBalance?: string;
marketCap?: string;
volume?: string;
holders?: number;
percentChange?: number;
};Notes
Use
displayBalancefor UI,balancefor programmatic logic.Market data fields (
usdPrice,percentChange,marketCap) are optional enrichment — not guaranteed for every token.Requires an active connection. If the wallet just initialised, run
status()first to confirmconnected.
Last updated