# Getting Accounts Balance

In the basic examples we still show how to use SignumJS depending the way you are using SignumJS, i.e. imported via NodeJS package manager or as minified bundle. In case you haven't read about the module system, take a quick look there:

{% content-ref url="/pages/5LpyrKz8NZepdbWjzEW9" %}
[Modules](/signumjs/getting-started/modules.md)
{% endcontent-ref %}

{% hint style="info" %}
A fully working example is available [here](https://github.com/signum-network/signumjs/blob/main/examples/nodejs/basic/getAccountBalance.js)
{% endhint %}

Following functions from SignumJS are used in this example&#x20;

* [composeApi](https://signum-network.github.io/signumjs/modules/core_api.html#composeapi) function to create the api instance
* [api.account.getAccountBalance](https://signum-network.github.io/signumjs/interfaces/core_api.accountapi.html#getaccountbalance) function to fetch the accounts balance from the blockchain
* [Address](https://signum-network.github.io/signumjs/classes/core.address.html) Value Object to parse and convert the given address&#x20;
* [Amount](https://signum-network.github.io/signumjs/classes/util.amount.html) Value Object to convert between Planck and Signa

{% tabs %}
{% tab title="Javascript" %}

```javascript
const {Address, composeApi} = require("@signumjs/core")
const {Amount} = require("@signumjs/util")

// Create the Api instance to connect to a blockchain node
const api = composeApi({
    nodeHost: "https://europe.signum.network"
});

async function getBalance(account) {
    // All API calls are asynchronous
    // The recommended pattern is using async/await
    // This makes exception handling easy using try/catch
    try {
        // We just create an address instance of incoming account string, which
        // might be the numeric id or an address like 'S-ABCD....'
        // It throws an error, if the input is not a valid address or account id
        const address = Address.create(account)
    
        // Now, we call the getAccountBalance method
        const {balanceNQT} = await api.account.getAccountBalance(address.getNumericId());

        // all amounts coming from the blockchain are expressed in Planck 
        // 1 SIGNA = 100000000 Planck
        // so we need to convert them using the Amount Value Object class
        const balance = Amount.fromPlanck(balanceNQT)
        
        // Print it to the console
        console.info(`Balance of ${address.getReedSolomonAddress()} is:`, balance.toString())
    } catch (e) {
        console.error(e.message)
    }
}
```

{% endtab %}

{% tab title="Typescript" %}

```typescript
import {Address, composeApi} from "@signumjs/core"
import {Amount} from "@signumjs/util"

// Create the Api instance to connect to a blockchain node
const api = composeApi({
    nodeHost: "https://europe.signum.network"
});

async function getBalance(account: string) : Promise<void> {
    // All API calls are asynchronous
    // The recommended pattern is using async/await
    // This makes exception handling easy using try/catch
    try {
        // We just create an address instance of incoming account string, which
        // might be the numeric id or an address like 'S-ABCD....'
        // It throws an error, if the input is not a valid address or account id
        const address = Address.create(account)
    
        // Now, we call the getAccountBalance method
        const {balanceNQT} = await api.account.getAccountBalance(address.getNumericId());

        // all amounts coming from the blockchain are expressed in Planck 
        // 1 SIGNA = 100000000 Planck
        // so we need to convert them using the Amount Value Object class
        const balance = Amount.fromPlanck(balanceNQT)
        
        // Print it to the console
        console.info(`Balance of ${address.getReedSolomonAddress()} is:`, balance.toString())
    } catch (e) {
        console.error(e.message)
    }
}
```

{% endtab %}

{% tab title="<script/>" %}

```javascript
// you need to have imported in your index.html:
/*
<script src='https://cdn.jsdelivr.net/npm/@signumjs/core/dist/signumjs.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/@signumjs/util/dist/signumjs.util.min.js'></script>
*/

// Create the Api instance to connect to a blockchain node
const api = sig$.composeApi({
    nodeHost: "https://europe.signum.network"
});

async function getBalance(account) {
    // All API calls are asynchronous
    // The recommended pattern is using async/await
    // This makes exception handling easy using try/catch
    try {
        // We just create an address instance of incoming account string, which
        // might be the numeric id or an address like 'S-ABCD....'
        // It throws an error, if the input is not a valid address or account id
        const address = sig$.Address.create(account)
    
        // Now, we call the getAccountBalance method
        const {balanceNQT} = await api.account.getAccountBalance(address.getNumericId());

        // all amounts coming from the blockchain are expressed in Planck 
        // 1 SIGNA = 100000000 Planck
        // so we need to convert them using the Amount Value Object class
        const balance = sig$util.Amount.fromPlanck(balanceNQT)
        
        // Print it to the console
        console.info(`Balance of ${address.getReedSolomonAddress()} is:`, balance.toString())
    } catch (e) {
        console.error(e.message)
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://signum-network.gitbook.io/signumjs/recipes/basics/getting-accounts-balance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
