Numbers Protocol
Search
⌃K
⚒

Fetch NUM balance

On Numbers Mainnet

To fetch NUM balance on Mainnet for a specific wallet, you can use the following API
API Endpoint: https://eoodjeosrg20qti.m.pipedream.net
​
Cost: 0, free to use
​
POST /
​
Description:
This endpoint allows you to create a new wallet.
​
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:
Python
Javacript
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)
​
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);
});
​
​
Replace the wallet in the examples to any wallet address you prefer.

Source code with nodejs14.x:

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:
API Endpoint: https://eoiu9t1jdjlxx5l.m.pipedream.net
​
Cost: 0, free to use
​
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 to register and acquire it.
More examples can be found below:
Python
Javascript
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)
​
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);
});
​
​
​