Explorer
The explorer API provides convinience methods to interact with the underlying blockchain via a bootstrap node. It also provides a mechanism to validate the NKN Address for correctness.
#
Valid AddressCheck if the provided address is structurally valid or not
String address = "<nknAddress>";boolean isValid = NKNExplorer.isAddressValid(address);if ( isValid ){ System.out.println("Address is valid");} else { System.out.println("Address is not valid");}
#
Wallet#
Resolve NameResolve a friendly name and get the corresponding NKN Address from the naming service.
String nknAddress = NKNExplorer.Wallet.resolveNamedAddress("friendlyname");
#
Query BalanceQuery the balance of an NKN Address
BigDecimal balance = NKNExplorer.Wallet.queryBalance("<nknAddress>");
#
Get NonceGet the nonce
long nonce = NKNExplorer.Wallet.getNonce("<nknAddress>");
#
Blockchain#
Get Block CountGet the block count
int blockCount = NKNExplorer.BlockChain.getBlockCount();
#
Get Latest Block HashGet the hash corresponding to the latest block
NKNExplorer.BlockChain.LatestBlockHash latestBlockHash = NKNExplorer.BlockChain.getLatestBlockHash();System.out.println(latestBlockHash.hash);System.out.println(latestBlockHash.height);
#
Subscription#
Get SubscribersGet a list of subscribers for a given topic.
String topic = "topicName";final NKNExplorer.Subscription.Subscriber[] subscribers = NKNExplorer.Subscription.getSubscribers(topic);System.out.println("Subscribers of '" + topic + "':");for (NKNExplorer.Subscription.Subscriber subscriber : subscribers) { System.out.println("Subscriber Identifier: " + subscriber.fullClientIdentifier); System.out.println("Meta: " + subscriber.meta);
}System.out.println("Total: " + subscribers.length + " subscribers");
tip
There is an overloaded method available to get subscribers which gives the option to filter subscribers basis offset
, limit
, metadata
, transaction pool
along with topic
.
#
Get Subscriber CountGet the number of subscribers subscribed to a topic
String topic = "topicName";int subscriberCount = NKNExplorer.Subscription.getSubscriberCount(topic);
#
Get Subscription DetailsGet details of the subscription for a subscriber
String topic = "topicName";String subscriberIdentifier = "identifier";NKNExplorer.Subscription.SubscriptionDetail subscriptionDetail = NKNExplorer.Subscription.getSubscriptionDetail(topic, subscriberIdentifier);
System.out.println("Subscriber Identifier: " + subscriptionDetail.fullClientIdentifier);System.out.println("Topic: " + subscriptionDetail.topic);System.out.println("Meta: " + subscriptionDetail.meta);System.out.println("Expires At: " + subscriptionDetail.expiresAt);