# Interact With Node
Use you can Assets and Address API methods.
# Assets API
You can get:
- Asset Balance Distribution.
- All Asset Balances for an Address.
- Balance of a Specific Asset.
- Asset Details.
- Non-Fungible Tokens (NFTs) at an Address.
# Asset Balance Distribution
Endpoint: GET /assets/{assetId}/distribution/{height}/limit/{limit}
async function getAssetDistributionRaw(
assetId: string,
limit = 100
): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl = 'https://nodes-testnet.wavesnodes.com';
// Get latest block height.
const heightResp = await fetch(`${nodeUrl}/blocks/height`);
const heightData: { height: number } = await heightResp.json();
const height = heightData.height - 1;
// Build the asset distribution URL.
const url = `${nodeUrl}/assets/${assetId}/distribution/${height}/limit/${limit}`;
const resp = await fetch(url);
// Read the raw response as text.
const text: string = await resp.text();
// Regex to find all the relevant entries.
const entryRegex = /"([1-9A-HJ-NP-Za-km-z]{30,})":(\d+)/g;
// Print the results.
console.log('––––––––––––––––––––––––––––––––––––––');
console.log('Asset Distribution (address: quantity):');
let match: RegExpExecArray | null;
while ((match = entryRegex.exec(text)) !== null) {
const address: string = match[1];
const balanceLamports: number = Number(match[2]);
const balanceInWaves: number = balanceLamports / 100;
console.log(`${address}: ${balanceInWaves.toFixed(2)}`);
}
// Check if more pages are available for pagination.
if (text.includes('"hasNext":true')) {
const lastItemMatch = /"lastItem":"(.*?)"/.exec(text);
if (lastItemMatch) {
console.log(`\nMore pages available. Last item: ${lastItemMatch[1]}`);
}
}
} catch (error) {
console.error('Error:', error);
}
}
// Specify an asset ID.
const assetId = 'PASTE AN ASSET ID';
getAssetDistributionRaw(assetId);
# All Asset Balances for an Address
Endpoint: GET /assets/balance/{address}
async function getAllAssetBalancesForAddress(address: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the URL for fetching all asset balances for the address.
const url: string = `${nodeUrl}/assets/balance/${address}`;
// Fetch the response.
const resp: Response = await fetch(url);
const data: {
address: string;
balances: { assetId: string; balance: number }[];
} = await resp.json();
// Extract the balances' array from response.
const balances = data.balances || [];
console.log('––––––––––––––––––––––––––––––––––––––');
console.log(`All Asset Balances for Address: ${address}`);
// Print the results.
for (const b of balances) {
const assetId: string = b.assetId;
const raw: number = Number(b.balance);
const formatted: number = raw / 100;
console.log(`Asset ID: ${assetId}, Balance: ${formatted.toFixed(2)}`);
}
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address: string = 'PASTE AN ADDRESS';
getAllAssetBalancesForAddress(address);
# Balance of a Specific Asset
Endpoint: GET /assets/balance/{address}/{assetId}
async function getBalanceOfSpecificAsset(address: string, assetId: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/assets/balance/${address}/${assetId}`;
// Fetch the response.
const resp: Response = await fetch(url);
const data: {
address: string;
assetId: string;
balance: number;
} = await resp.json();
// Extract the raw balance and format it.
const raw: number = Number(data.balance);
const formatted: number = raw / 100;
// Print the result.
console.log('––––––––––––––––––––––––––––––––––––––');
console.log(`Asset ${data.assetId} balance at ${data.address}: ${formatted.toFixed(2)}`);
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address: string = 'PASTE AN ADDRESS';
// Specify an asset ID.
const assetId: string = 'PASTE AN ASSET ID';
getBalanceOfSpecificAsset(address, assetId);
# Asset Details
Endpoint: GET /assets/details/{assetId}
async function getAssetDetails(assetId: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/assets/details/${assetId}`;
// Fetch the response.
const resp: Response = await fetch(url);
const data: {
name: string;
description: string;
decimals: number;
reissuable: boolean;
issuer: string;
} = await resp.json();
// Print the results.
console.log('––––––––––––––––––––––––––––––––––––––');
console.log(`Name: ${data.name}`);
console.log(`Description: ${data.description}`);
console.log(`Decimals: ${data.decimals}`);
console.log(`Reissuable: ${data.reissuable}`);
console.log(`Issuer: ${data.issuer}`);
} catch (error) {
console.error('Error:', error);
}
}
// Specify an asset ID.
const assetId: string = 'PASTE AN ASSET ID';
getAssetDetails(assetId);
# Non-Fungible Tokens (NFTs) at an Address
Endpoint: GET /assets/nft/{address}/limit/{limit}
async function getNFTsByAddress(address: string, limit: number = 100): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/assets/nft/${address}/limit/${limit}`;
// Fetch the response.
const resp: Response = await fetch(url);
const nfts: {
assetId: string;
name: string;
description: string;
quantity: number;
}[] = await resp.json();
// Print the results.
console.log('––––––––––––––––––––––––––––––––––––––');
console.log(`NFTs at Address: ${address}`);
for (const nft of nfts) {
console.log(`ID: ${nft.assetId} | Name: ${nft.name} | Description: ${nft.description} | Quantity: ${nft.quantity}`);
}
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address: string = 'PASTE AN ADDRESS';
getNFTsByAddress(address);
# Addresses API
You can get:
- All Addresses in the Node Wallet.
- A Range of Addresses.
- WAVES Balance of an Address.
- WAVES Balance with Confirmations.
- Detailed Balance Information.
- Balances for Multiple Addresses.
- Account Data Entries by Address.
- Data Entry by Key.
- Script Information of an Account.
# All Addresses in the Node Wallet
Endpoint: GET /addresses
async function getAllNodeWalletAddresses(): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/addresses`;
// Fetch the response.
const resp: Response = await fetch(url);
const addresses: string[] = await resp.json();
// Print the results.
console.log('Node Wallet Addresses:');
addresses.forEach((addr: string): void => {
console.log(addr);
});
} catch (error) {
console.error('Error:', error);
}
}
getAllNodeWalletAddresses();
# Range of Addresses
Endpoint: GET /addresses/seq/{from}/{to}
async function getAddressRange(from: number, to: number): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/addresses/seq/${from}/${to}`;
// Fetch the response.
const resp: Response = await fetch(url);
const addresses: string[] = await resp.json();
// Print the results.
console.log(`Addresses ${from} to ${to}:`);
addresses.forEach((address: string): void => {
console.log(address);
});
} catch (error) {
console.error('Error:', error);
}
}
// Wallet index range.
const from = 0;
const to = 4;
getAddressRange(from, to);
# WAVES Balance of an Address
Endpoint: GET /addresses/balance/{address}
async function getWavesBalance(address: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/addresses/balance/${address}`;
// Fetch the response.
const resp: Response = await fetch(url);
const data: { balance: number } = await resp.json();
// Convert balance to WAVES.
const wavesBalance = data.balance / 1e8;
// Print the result.
console.log(`Balance at ${address}: ${wavesBalance.toFixed(8)} WAVES`);
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address = 'PASTE AN ADDRESS';
getWavesBalance(address);
# WAVES Balance with Confirmations
Endpoint: GET /addresses/balance/{address}/{confirmations}
async function getWavesBalanceWithConfirmations(address: string, confirmations: number): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/addresses/balance/${address}/${confirmations}`;
// Fetch the response.
const resp: Response = await fetch(url);
const data: { balance: number } = await resp.json();
// Convert balance to WAVES.
const wavesBalance = data.balance / 1e8;
// Print the result.
console.log(`Balance at ${address} (>= ${confirmations} confirmations): ${wavesBalance.toFixed(8)} WAVES`);
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address = 'PASTE AN ADDRESS';
// Specify the number of confirmations.
const confirmations = 2;
getWavesBalanceWithConfirmations(address, confirmations);
# Detailed Balance Information
Endpoint: GET /addresses/balance/details/{address}
NOTE: The method shows the available, regular, generating, and effective account balances.
async function getDetailedBalanceInfo(address: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl: string = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url: string = `${nodeUrl}/addresses/balance/details/${address}`;
// Fetch the response.
const resp: Response = await fetch(url);
const info: {
regular: number;
available: number;
generating: number;
effective: number;
} = await resp.json();
// Print the results.
console.log(`Regular: ${(info.regular / 1e8).toFixed(8)} WAVES`);
console.log(`Available: ${(info.available / 1e8).toFixed(8)} WAVES`);
console.log(`Generating: ${(info.generating / 1e8).toFixed(8)} WAVES`);
console.log(`Effective: ${(info.effective / 1e8).toFixed(8)} WAVES`);
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address = 'PASTE AN ADDRESS';
getDetailedBalanceInfo(address);
# Balances for Multiple Addresses
Endpoint: POST /addresses/balance
async function getBalancesForMultipleAddresses(addresses: string[]): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/addresses/balance"
* - Testnet: "https://nodes-testnet.wavesnodes.com/addresses/balance"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/addresses/balance"
*/
const nodeUrl = 'https://nodes-testnet.wavesnodes.com/addresses/balance';
// Prepare the POST request body.
const body = JSON.stringify({ addresses });
// Send the POST request.
const resp = await fetch(nodeUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body,
});
// Parse the response.
const results: { address: string; balance: number }[] = await resp.json();
// Print the results.
for (let i = 0; i < addresses.length; i++) {
const entry = results[i];
const balance = entry.balance / 1e8;
console.log(`${addresses[i]}: ${balance.toFixed(8)} WAVES`);
}
} catch (error) {
console.error('Error:', error);
}
}
// Specify account addresses.
const addresses = [
'PASTE 1ST ADDRESS',
'PASTE 2ND ADDRESS'
// ...
];
getBalancesForMultipleAddresses(addresses);
# Account Data Entries by Address
Endpoint: GET /addresses/data/{address}
async function getAccountDataEntries(address: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url = `${nodeUrl}/addresses/data/${address}`;
// Fetch the response.
const resp = await fetch(url);
// Parse the JSON response.
type DataEntry = { key: string; type: string; value: any };
const entries: DataEntry[] = await resp.json();
// Print the results.
entries.forEach(e => {
console.log(`${e.key} (${e.type}): ${e.value}`);
});
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address = 'PASTE AN ADDRESS';
getAccountDataEntries(address);
# Data Entry by Key
Endpoint: GET /addresses/data/{address}/{key}
async function getDataEntryByKey(address: string, key: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url = `${nodeUrl}/addresses/data/${address}/${key}`;
// Fetch the response.
const resp = await fetch(url);
// Parse the JSON response.
type DataEntry = { key: string; type: string; value: any };
const entry: DataEntry = await resp.json();
// Print the results.
console.log(`${entry.key} (${entry.type}): ${entry.value}`);
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address = 'PASTE AN ADDRESS';
// Specify an account key.
const key = 'PASTE AN ACCOUNT KEY';
getDataEntryByKey(address, key);
# Script Information of an Account
Endpoint: GET /addresses/scriptInfo/{address}
async function getScriptInfo(address: string): Promise<void> {
try {
/*
* Specify the network node URL:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
const nodeUrl = 'https://nodes-testnet.wavesnodes.com';
// Build the request URL.
const url = `${nodeUrl}/addresses/scriptInfo/${address}`;
// Fetch the response.
const resp = await fetch(url);
// Parse the JSON response.
type ScriptInfoResponse = {
script: string | null;
complexity?: number;
extraFee?: number;
};
const info: ScriptInfoResponse = await resp.json();
// Print the results.
console.log(`Has Script: ${info.script !== null}`);
if (info.script !== null) {
console.log(`Complexity: ${info.complexity}`);
console.log(`Extra Fee: ${info.extraFee}`);
}
} catch (error) {
console.error('Error:', error);
}
}
// Specify an address.
const address = 'PASTE AN ADDRESS';
getScriptInfo(address);