Account Methods

Account methods of Azoth SDK for getting balance and user information

balanceOf()

Retrieves the token balance of an account in the AzothPay system.

async balanceOf(account?: string): Promise<number>

Parameters:

  • account (optional): The address to check the balance of. If not provided, uses the connected signer’s address.

Returns:

  • The account balance in its raw blockchain format. Use formatOutput() to convert to a human-readable number.

Example:

// Get raw balance
const rawBalance = await azoth.balanceOf();

// Convert to human-readable format
const balance = formatOutput(BigInt(rawBalance), 18);
console.log(`My balance: ${balance} USDT`);

getUserInfo()

Gets detailed information about a user’s account.

async getUserInfo(account?: string): Promise<UserInfo>

Parameters:

  • account (optional): The address to get info for. If not provided, uses the connected signer’s address.

Returns:

  • A UserInfo object with the following properties:

    • balance: The account balance in raw blockchain format

    • incomeRate: The rate at which the account is receiving subscriptions (raw format)

    • outgoingRate: The rate at which the account is paying subscriptions (raw format)

    • updated: The timestamp when the account was last updated

Note: incomeRate and outgoingRate are raw blockchain values. Use utility functions to convert them into human-readable values (e.g. per month)

// Get raw user info
const userInfo = await azoth.getUserInfo();

// Convert to human-readable format
const formattedUserInfo = {
  balance: formatOutput(BigInt(userInfo.balance), 18),
  incomeRate: convertRateToPeriod(
    Number(formatOutput(userInfo.incomeRate, 18)), 
    RatePeriod.MONTH
  ),
  outgoingRate: convertRateToPeriod(
    Number(formatOutput(userInfo.outgoingRate, 18)), 
    RatePeriod.MONTH
  ),
  updated: new Date(Number(userInfo.updated) * 1000).toLocaleString()
};

console.log(`Balance: ${formattedUserInfo.balance} USDT`);
console.log(`Income rate: ${formattedUserInfo.incomeRate} USDT per month`);
console.log(`Outgoing rate: ${formattedUserInfo.outgoingRate} USDT per month`);
console.log(`Last updated: ${formattedUserInfo.updated}`);

Last updated