# \[NUM] Fetch NUM balance

## On Numbers Mainnet

To fetch NUM balance on Mainnet for a specific wallet, you can use the following API

```javascript
API Endpoint: https://eoodjeosrg20qti.m.pipedream.net

Cost: 0, free to use

POST /

Description:
This endpoint allows you fetch NUM balance on Numbers Mainnet

Headers:
Content-Type: application/json

Request Body:
{
    "wallet": "0x1234567890abcdef1234567890abcdef12345678"
}

Examples:
curl -X POST https://eoodjeosrg20qti.m.pipedream.net \
     -H "Content-Type: application/json" \
     -d '{"wallet": "0x1234567890abcdef1234567890abcdef12345678"}'


```

In the API call, the Request body needs to have a key-value pair as "wallet" and a valid wallet address as value. More examples can be found below:

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

```python
import json
import requests

url = "https://eoodjeosrg20qti.m.pipedream.net"
headers = {"Content-Type": "application/json"}
payload = {"wallet": "0x1234567890abcdef1234567890abcdef12345678"}

response = requests.post(url, headers=headers, data=json.dumps(payload))

print(response.text)

```

{% endtab %}

{% tab title="Javacript" %}

```javascript
const data = {wallet: '0x1234567890abcdef1234567890abcdef12345678'};

fetch('https://eoodjeosrg20qti.m.pipedream.net', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
  console.log(data);
})
.catch(error => {
  console.error(error);
});


```

{% endtab %}
{% endtabs %}

Replace the wallet in the examples to any wallet address you prefer.

### Source code with nodejs14.x:

```javascript
import { providers, BigNumber } from "ethers";

async function getUserNumBalance(userWallet) {
  // Create a provider to connect to the Ethereum network
  const numProvider = new providers.JsonRpcProvider(
    "https://mainnetrpc.num.network"
  );
  // Get the balance of the wallet as a BigNumber object
  const userNumBalanceObj = await numProvider.getBalance(userWallet);

  // Convert the balance from wei to Ether
  const weiPerEther = BigNumber.from(10).pow(14);
  const balanceInEther = userNumBalanceObj.div(weiPerEther)/10000;

  // Convert the balance to a string and return it
  const userNumBalance = balanceInEther.toFixed(4);
  return userNumBalance;
}

export default defineComponent({
    async run({ steps, $ }) {
        // Get the user address from the previous step
    const userAddress = steps.trigger.event.body.wallet;

    // Call the getUserNumBalance() function with the user address
    const balance = await getUserNumBalance(userAddress);

    // Return the balance to use it in future steps
    await $.respond({
      status: 200,
      headers: {},
      body: {"balance": balance},
    })
  },
});
```

## On All Networks

To fetch NUM balance on ***ALL NETWORKS*** for a specific wallet, you can use the following API with your Capture Token:

```javascript
API Endpoint: https://eoiu9t1jdjlxx5l.m.pipedream.net

Cost: 0.01 NUM

POST /

Description:
This endpoint allows you to create a new wallet with the given address.

Headers:
Content-Type: application/json
Authorization: token YOUR_CAPTURE_TOKEN

Authentication:
The API requires a valid token for Authorization. 
You can pass it in the headers of the request using the following format: 
"Authorization: token YOUR_CAPTURE_TOKEN"

Request Body:
{
    "wallet": "0x1234567890abcdef1234567890abcdef12345678"
}

Examples:
curl -X POST https://eoiu9t1jdjlxx5l.m.pipedream.net \
     -H "Content-Type: application/json" \
     -H "Authorization: token YOUR_CAPTURE_TOKEN" \
     -d '{"wallet": "0x1234567890abcdef1234567890abcdef12345678"}'


```

In the API call, the Request body needs to have a key-value pair as "wallet" and a valid wallet address as value. The API will return the NUM balance for the specified wallet. Please note, this API requires authorization with your ***Capture Token***. Follow [the instructions](https://docs.captureapp.xyz/about-capture/create-an-account#capture-token) to register and acquire it.

More examples can be found below:

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

```python
import json
import requests

url = 'https://eoiu9t1jdjlxx5l.m.pipedream.net'
headers = {
    'Authorization': 'token YOUR_CAPTURE_TOKEN',
    'Content-Type': 'application/json'
}
data = {"wallet": "0x1234567890abcdef1234567890abcdef12345678"}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.content)

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const url = 'https://eoiu9t1jdjlxx5l.m.pipedream.net';
const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'token 1bd90eba5b902e6fd05701f49a8d8a4bf814cfcf'
};
const body = JSON.stringify({ wallet: '0x1234567890abcdef1234567890abcdef12345678' });

fetch(url, { method: 'POST', headers, body })
  .then((response) => response.json())
  .then((data) => {
    console.log(data);
  })
  .catch((error) => {
    console.error(error);
  });


```

{% 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://numbersprotocol.gitbook.io/about/developers/more-tools/num-fetch-num-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.
