Esc

Balances

Fetch token balances for the connected wallet with optional filtering.

import { mega } from '@megaeth-labs/wallet-sdk';

// Omit tokens to get every token the account holds.
const balances = await mega.balances({ tokens: ['0x2715b6d04b6a0AB227631019899282a585Be410F'] });

for (const token of balances) {
    console.log(token.symbol, token.displayBalance);
}
Runs on testnet with your wallet
ts
interface BalancesRequest {
    tokens?: string[];
}

// Resolves to one entry per token
interface OwnedTokenResponse {
    name: string;
    symbol: string;
    decimals: number;
    address: string;
    image?: string;
    balance: string;
    displayBalance: string;
    usdPrice?: string;
    usdBalance?: string;
}