# getBalance

## Description

The `getBalance` function allows developers to retrieve the account balance of a specified public key on the Casper blockchain.

## Parameters

| Parameter   | Type   | Description                                               |
| ----------- | ------ | --------------------------------------------------------- |
| `publicKey` | string | The public key of the account to retrieve the balance for |
| `RPC_API`   | string | The RPC API endpoint of the Casper network                |

## Response

| Name      | Type   | Description                            |
| --------- | ------ | -------------------------------------- |
| `balance` | string | The balance of the account as a string |

## Example Request and Response

### Prerequisites

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

You can install NO.AI SDK using either **`npm`** or **`yarn`**. Use the following commands to install NO.AI SDK:

```sh
npm install @nest25/casper-lib
OR
yarn add @nest25/casper-lib
```

### Request

Here is an example of how to make a `getBalance` request using the NO.AI SDK:

```javascript
// import Nest25 Casper library
const { Casper } = require('@nest25/casper-lib');
// create a new Casper instance
const casper = new Casper();

const publicKey = '013a156a50fc6284ba436aedeaf96b55ac1a0c57ee9f8a46bf1c6518afe9b2f56c';
const RPC_API = 'https://rpc.testnet.casperlabs.io/rpc';

async function main() {
  let balance = await casper.getBalance(publicKey, RPC_API);
  console.log({ balance });
}
// call main function
main();
```

### Response

```sh
 { balance: '1975238447828' }
```

## Use Cases

* **Wallets:** The function can be used by cryptocurrency wallets to display the account balance of the user.
* **DApps:** The function can be used by decentralized applications on the Casper network to retrieve the account balance of a user.
* **Exchanges:** The function can be used by cryptocurrency exchanges to check the balance of user accounts before allowing them to make trades.

<br>
