UNPKG

blub-sdk

Version:

A modular SDK for interacting with the BLUB ecosystem on the Sui blockchain.

31 lines (30 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBlubBalance = getBlubBalance; const client_1 = require("../../utils/client"); const constants_1 = require("../../utils/constants"); /** * Retrieves the BLUB token balance for a given wallet address. * * @param owner - The address to query the BLUB balance for. * @returns The total BLUB balance as a bigint. */ function getBlubBalance(owner) { return getCoinBalance(owner, constants_1.BLUB_COINTYPE); } /** * Retrieves the balance of any given coin type for a specific wallet address. * * @param owner - The wallet address to query. * @param coinType - The full coin type string (e.g., `0x...::blub::BLUB`). * @param client - Optional SuiClient instance (defaults to `defaultSuiClient`). * @returns The total balance for the specified coin type as a bigint. */ async function getCoinBalance(owner, coinType, client = client_1.defaultSuiClient) { if (typeof client.getBalance === "function") { const resp = await client.getBalance({ owner, coinType }); return BigInt(resp.totalBalance ?? 0); } const coins = await client.getCoins({ owner, coinType }); return coins.data.reduce((sum, c) => sum + BigInt(c.balance), BigInt(0)); }