# 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}
package com.example;
// Necessary imports.
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.*;
public class AssetBalanceDistribution {
public static void main(String[] args) throws Exception {
// Specify an asset ID.
String assetId = "PASTE AN ASSET ID";
// Specify the maximum number of entries to return.
int limit = 100;
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Get the latest block height.
URL heightUrl = new URL(nodeUrl + "/blocks/height");
HttpURLConnection heightCon = (HttpURLConnection) heightUrl.openConnection();
Scanner heightScanner = new Scanner(new InputStreamReader(heightCon.getInputStream()));
String heightResp = heightScanner.nextLine();
heightScanner.close();
// Decrement to get the last full block height.
int height = Integer.parseInt(heightResp.replaceAll("\\D", "")) - 1;
// Build the URL for asset distribution.
String url = nodeUrl + "/assets/" + assetId + "/distribution/" + height + "/limit/" + limit;
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
// Analyze the output.
Scanner scanner = new Scanner(new InputStreamReader(con.getInputStream()));
Pattern entry = Pattern.compile("\"([1-9A-HJ-NP-Za-km-z]{30,})\":(\\d+)");
// Print the results.
System.out.println("––––––––––––––––––––––––––––––––––––––");
System.out.println("Asset Distribution (address: quantity):");
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
Matcher matcher = entry.matcher(line);
while (matcher.find()) {
String address = matcher.group(1);
long balanceLamports = Long.parseLong(matcher.group(2));
double balanceInWaves = balanceLamports / 100.0;
System.out.printf("%s: %.2f\n", address, balanceInWaves);
}
// Check if more pages are available.
if (line.contains("\"hasNext\":true")) {
Matcher lastItem = Pattern.compile("\"lastItem\":\"(.*?)\"").matcher(line);
if (lastItem.find()) {
System.out.printf("\nMore pages available. Last item: %s\n", lastItem.group(1));
}
}
}
scanner.close();
}
}
# All Asset Balances for an Address
Endpoint: GET /assets/balance/{address}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AllAssetBalancesForAddress {
public static void main(String[] args) throws Exception {
// Specify an asset ID.
String address = "PASTE AN ASSET ID";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the URL.
URL url = new URL(nodeUrl + "/assets/balance/" + address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> resp = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String, Object>>() {}
);
List<Map<String,Object>> balances = (List<Map<String,Object>>) resp.get("balances");
// Print the results.
System.out.println("––––––––––––––––––––––––––––––––––––––");
System.out.println("All Asset Balances for Address: " + address);
for (Map<String,Object> b : balances) {
String assetId = (String) b.get("assetId");
long raw = ((Number) b.get("balance")).longValue();
double formatted = raw / 1e2;
System.out.printf("Asset ID: %s, Balance: %.2f\n", assetId, formatted);
}
}
}
# Balance of a Specific Asset
Endpoint: GET /assets/balance/{address}/{assetId}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class BalanceOfSpecificAsset {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
// Specify an asset ID.
String assetId = "PASTE AN ASSET ID";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/assets/balance/" + address + "/" + assetId);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map and format the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> resp = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
long raw = ((Number)resp.get("balance")).longValue();
double formatted = raw / 1e2;
// Print the results.
System.out.println("––––––––––––––––––––––––––––––––––––––");
System.out.printf(
"Asset %s balance at %s: %.2f\n",
resp.get("assetId"), resp.get("address"), formatted
);
}
}
# Asset Details
Endpoint: GET /assets/details/{assetId}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AssetDetails {
public static void main(String[] args) throws Exception {
// Specify an asset ID.
String assetId = "PASTE AN ASSET ID";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/assets/details/" + assetId);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> d = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
// Print the results.
System.out.println("––––––––––––––––––––––––––––––––––––––");
System.out.printf("Name: %s%nDescription: %s%nDecimals: %d%nReissuable: %b%nIssuer: %s%n",
d.get("name"), d.get("description"), ((Number)d.get("decimals")).intValue(), d.get("reissuable"), d.get("issuer")
);
}
}
# Non-Fungible Tokens (NFTs) at an Address
Endpoint: GET /assets/nft/{address}/limit/{limit}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class NFTsByAddress {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
// Specify the maximum number of entries to return.
int limit = 100;
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/assets/nft/" + address + "/limit/" + limit);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
List<Map<String,Object>> nfts = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<List<Map<String,Object>>>() {}
);
// Print the results.
System.out.println("––––––––––––––––––––––––––––––––––––––");
System.out.println("NFTs at Address: " + address);
for (Map<String,Object> nft : nfts) {
// The results will be printed if NFTs are found at the given address.
System.out.printf("ID: %s | Name: %s | Description: %s | Quantity: %d%n",
nft.get("assetId"), nft.get("name"), nft.get("description"), ((Number)nft.get("quantity")).intValue());
}
}
}
# 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
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class GetAllNodeWalletAddresses {
public static void main(String[] args) throws Exception {
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
List<String> addresses = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<List<String>>() {}
);
// Print the results.
System.out.println("Node Wallet Addresses:");
addresses.forEach(addr -> System.out.println(addr));
}
}
# Range of Addresses
Endpoint: GET /addresses/seq/{from}/{to}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class GetAddressRange {
public static void main(String[] args) throws Exception {
// Wallet index number.
int from = 0, to = 4;
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/seq/" + from + "/" + to);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
List<String> addresses = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<List<String>>() {}
);
// Print the results.
System.out.printf("Addresses %d to %d:\n", from, to);
addresses.forEach(System.out::println);
}
}
# WAVES Balance of an Address
Endpoint: GET /addresses/balance/{address}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class WavesBalance {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/balance/" + address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> resp = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
long raw = ((Number)resp.get("balance")).longValue();
// Print the results.
System.out.printf("Balance at %s: %.8f WAVES\n", address, raw / 1e8);
}
}
# WAVES Balance with Confirmations
Endpoint: GET /addresses/balance/{address}/{confirmations}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class WavesBalanceWithConfirmations {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRES";
// Enter the number of confirmations.
int confirmations = 2; // Number example.
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/balance/" + address + "/" + confirmations);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> resp = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
long raw = ((Number)resp.get("balance")).longValue();
// Print the results.
System.out.printf("Balance at %s (>= %d confirmations): %.8f WAVES\n", address, confirmations, raw / 1e8);
}
}
# Detailed Balance Information
Endpoint: GET /addresses/balance/details/{address}
NOTE: The method shows the available, regular, generating, and effective account balances.
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class DetailedBalanceInfo {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/balance/details/" + address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> info = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
// Print the results.
System.out.printf("Regular: %.8f WAVES%n", ((Number)info.get("regular")).doubleValue()/1e8);
System.out.printf("Available: %.8f WAVES%n", ((Number)info.get("available")).doubleValue()/1e8);
System.out.printf("Generating: %.8f WAVES%n", ((Number)info.get("generating")).doubleValue()/1e8);
System.out.printf("Effective: %.8f WAVES%n", ((Number)info.get("effective")).doubleValue()/1e8);
}
}
# Balances for Multiple Addresses
Endpoint: POST /addresses/balance
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class BalancesForMultipleAddresses {
public static void main(String[] args) throws Exception {
// Specify account addresses.
List<String> addresses = List.of(
"PASTE 1ST ADDRESS",
"PASTE 2ND ADDRESS"
// ...
);
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/addresses/balance"
* - Testnet: "https://nodes-testnet.wavesnodes.com/addresses/balance"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/addresses/balance"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com/addresses/balance";
// Map the data.
ObjectMapper mapper = new ObjectMapper();
byte[] body = mapper.writeValueAsBytes(Map.of("addresses", addresses));
// Build the request URL.
HttpURLConnection con = (HttpURLConnection) new URL(nodeUrl).openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
try (OutputStream os = con.getOutputStream()) {
os.write(body);
}
// Map the data.
List<Map<String, Object>> results = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<List<Map<String, Object>>>() {}
);
// Print the results.
for (int i = 0; i < addresses.size(); i++) {
Map<String, Object> balanceEntry = results.get(i);
double balance = ((Number) balanceEntry.get("balance")).doubleValue() / 1e8;
System.out.printf("%s: %.8f WAVES%n", addresses.get(i), balance);
}
}
}
# Account Data Entries by Address
Endpoint: GET /addresses/data/{address}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AccountDataEntries {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/data/" + address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
List<Map<String,Object>> entries = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<List<Map<String,Object>>>() {}
);
// Print the results.
entries.forEach(e -> System.out.printf("%s (%s): %s%n", e.get("key"), e.get("type"), e.get("value")));
}
}
# Data Entry by Key
Endpoint: GET /addresses/data/{address}/{key}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class DataEntryByKey {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
// Specify an account key.
String key = "PASTE AN ACCOUNT KEY";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/data/" + address + "/" + key);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> entry = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
// Print the results.
System.out.printf("%s (%s): %s%n", entry.get("key"), entry.get("type"), entry.get("value"));
}
}
# Script Information of an Account
Endpoint: GET /addresses/scriptInfo/{address}
package com.example;
// Necessary imports.
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class ScriptInfo {
public static void main(String[] args) throws Exception {
// Specify an account address.
String address = "PASTE AN ADDRESS";
/*
* Specify the network:
* - Mainnet: "https://nodes.wavesnodes.com/"
* - Testnet: "https://nodes-testnet.wavesnodes.com/"
* - Stagenet: "https://nodes-stagenet.wavesnodes.com/"
*/
String nodeUrl = "https://nodes-testnet.wavesnodes.com";
// Build the request URL.
URL url = new URL(nodeUrl + "/addresses/scriptInfo/" + address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Map the data.
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> info = mapper.readValue(
new InputStreamReader(con.getInputStream()),
new TypeReference<Map<String,Object>>() {}
);
// Print the results.
System.out.printf("Has Script: %b%n", info.get("script") != null);
if (info.get("script") != null) {
System.out.printf("Complexity: %d%nExtra Fee: %d%n", ((Number)info.get("complexity")).intValue(), ((Number)info.get("extraFee")).intValue());
}
}
}