Skip to content

getBalance

Action for getting a Starknet account's balance.

Import

import { getBalance } from "starkweb/core";

Usage

index.ts
import { getBalance } from "starkweb/core";
import { config } from "./config";
 
const balance = await getBalance(config, {
  address: "0x123...", 
});

Parameters

import { type GetBalanceParameters } from "starkweb/core";

address

Hex

The address of the account to get the balance for.

index.ts
import { getBalance } from "starkweb/core";
import { config } from "./config";
 
const balance = await getBalance(config, {
  address: "0x123...", 
});

chainId (optional)

Hex | undefined

The chain ID to get the balance from. If not provided, uses the current chain.

index.ts
import { getBalance } from "starkweb/core";
import { mainnet } from "starkweb/chains"; 
import { config } from "./config";
 
const balance = await getBalance(config, {
  address: "0x123...",
  chainId: mainnet.chain_id, 
});

Return Type

import { type GetBalanceReturnType } from "starkweb/core";

bigint

The account's balance in wei.

Example

example.ts
import { getBalance } from "starkweb/core";
import { mainnet, testnet } from "starkweb/chains"; 
import { config } from "./config";
 
// Get balance on current chain
const currentBalance = await getBalance(config, {
  address: "0x123...", 
});
console.log("Current balance:", currentBalance);
 
// Get balance on specific chain
const mainnetBalance = await getBalance(config, {
  address: "0x123...",
  chainId: mainnet.chain_id, 
});

Error

import { type GetBalanceErrorType } from "starkweb/core";

TanStack Query

import {
  type GetBalanceData,
  type GetBalanceQueryFnData,
  type GetBalanceQueryKey,
  type GetBalanceErrorType,
  type GetBalanceOptions,
  getBalanceQueryKey,
  getBalanceQueryOptions,
} from "starkweb/query";