0.0.9 • Published 9 months ago

@orbiter-finance/wallet-balance v0.0.9

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

BalanceQueryService

BalanceQueryService is a utility class for querying native and token balances across multiple blockchain networks. It utilizes the ExploreLinkProvider from the @orbiter-finance/explore-link package to interact with different blockchain endpoints.

Features

  • Cache mechanism for reusing instances of BalanceQueryService.
  • Asynchronous initialization with timeout handling.
  • Chain information retrieval with error handling.
  • Retry mechanism for fetching balances using multiple RPC URLs.

Installation

To install the package, use npm or yarn:

npm install @orbiter-finance/wallet-balance

or

yarn add @orbiter-finance/wallet-balance

Usage

Import the Service

import BalanceQueryService from './BalanceQueryService';

Initialize the Service

You need to initialize the service before making any balance queries.

const service = await BalanceQueryService.initializeService();
or 
const service = new BalanceQueryService(new ExploreLinkProvider());// yarn install @orbiter-finance/explore-link

Get Native Token Balance

To retrieve the native balance of a specific address on a specified chain:

const balance = await service.getNativeBalance(chainId, address);
console.log(`Native Balance: ${balance}`);

Get Token Balance

To retrieve the balance of a specific token for a given address:

const tokenBalance = await service.getTokenBalance(chainId, address, tokenAddress);
console.log(`Token Balance: ${tokenBalance}`);

Error Handling

Make sure to handle potential errors when using the service:

try {
    const balance = await service.getNativeBalance(chainId, address);
    console.log(`Native Balance: ${balance}`);
} catch (error) {
    console.error(`Error fetching balance: ${error.message}`);
}

License

JavaScript library for Orbiter Finance Wallet Balance

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.3

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.2

9 months ago

0.0.1

10 months ago