Help & Support

Balances

This guide explains how to fetch native and ERC20 token balances.

You MUST be authenticated as Account Owner or Account Manager to make this request.

Use the fetchBalancesBulk action to fetch a finite number of balances for the specific address.

import { evmAddress } from "@lens-protocol/client";import { fetchBalancesBulk } from "@lens-protocol/client/actions";
const result = await fetchBalancesBulk(sessionClient, {  address: evmAddress("0x1234…"),  tokens: [evmAddress("0x1234…"), evmAddress("0x5678…")],});
if (result.isErr()) {  return console.error(result.error);}
// Array<Erc20Amount | NativeAmount | Erc20BalanceError | NativeBalanceError>const balances = result.value;

This response differs slightly from others by providing a localized error for each balance that couldn’t be fetched. This enables more graceful error handling, allowing you to display some balances even if others fail.

Example
for (let balance of balances) {  switch (balance.__typename) {    case "Erc20Amount":      console.log(`${balance.value} ${balance.asset.symbol}`);      break;
    case "NativeAmount":      console.log(`${balance.value} ${balance.asset.symbol}`);
    case "Erc20BalanceError":    case "NativeBalanceError":      console.error(balance.reason);  }}