🔗getBalance

Description

The getBalance function takes a blockchain network name and an account address as inputs and returns the balance of that account in the specified cryptocurrency

Parameters

ParameterTypeDescription

blockchain

string

Takes a string parameter specifying the name of the blockchain network (For eg. bsc, polygon, eth, ava, gnosis, moonbeam)

address

string

The address for which to retrieve the balance

Response

PropertyTypeDescription

Promise<BigNumber>

BigNumber

Returns the current ether balance of the specified address on the specified blockchain network blockchain.

Example Request and Response

Prerequisites

Before making requests with Nest SDK, you must have it installed.

You can install Nest SDK using either npm or yarn. Use the following commands to install Nest SDK:

npm install @nest25/evm-chains-lib
OR
yarn add @nest25/evm-chains-lib

Request

Here is an example of how to make a getBalance request using the Nest SDK:

// import the Nest SDK
const { Wallet } = require('@nest25/evm-chains-lib');

// create a new wallet
const wallet = new Wallet();

// define the main function
const main = async () => {
    // get the balance of the contract
    let balance = await wallet.getBalance('gnosis', '0xE668C72D4C67236A712Ce69A91C74358586f31ed');

    // convert the balance to a string
    const balanceToString = balance.toString();
    // print the balance
    console.log(balanceToString);
};
// call the main function
main();

Response

 6803371899323

Use Cases

  • Wallet Balance: The function can be used to get the balance of a wallet address for a specific blockchain network, helping users to keep track of their crypto assets.

  • Payment Systems: Payment systems can use the function to verify the balance of a user's account before processing transactions, ensuring that the user has sufficient funds to complete the payment.

Last updated