For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 displayBalance for UI, balance for 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 confirm connected.

Last updated