Skip to content
John Smith edited this page Apr 26, 2020 · 4 revisions

WIKI Home -> Wallet API

A wallet is a collection of private and public key, which are required to do any operation on your behalf.

Wallet manipulation

Lets generate new wallet:

Wallet w = Wallet.createNew();

And save it, so we can access it in the future

w.save(new File("wallet.json"), "pwd");

Great, we have a wallet now. Let's get its address so other people can send us assets:

String address = w.getAddress(); // Used for sending assets

There are two more different ways to get an instance of Wallet

From private key:

Wallet w1 = Wallet.createFromPrivateKey(privKeyBytes);
Wallet w2 = Wallet.createFromPrivateKey(privKeyHexString);

Load from file:

Wallet w = Wallet.load(new File("wallet.json"), "pwd");

Both methods save and load are overloaded with saving/loading to/from Input/Output Stream, so you can load your wallet from a network or whatever, instead of a file. Or have your own save file with other stuff contain wallet as part of it.

Transactions

To submit a transaction, you need an instance on NKNTransaction. This can be obtained by

NKNTransaction tx = wallet.tx();

and on this tx you can submit any of the pre-implemented transactions:

String txId;
txId = tx.transferTo(to.getAddress(), new BigDecimal(amount));
txId = tx.registerName(name);
txId = tx.subscribe(topic, bucket, duration);

or submit your own, using tx.customTransaction(TransactionT)

Every transaction type has multiple methods with different arguments, all of which provide an option to add a fee to any transaction.

Explorer features

Explorer information that is public is packed in class NKNExplorer with following calls

NKNExplorer.queryBalance(address);
NKNExplorer.isAddressValid(address); // Doesn't require internet connection
NKNExplorer.resolveNamedAddress(name);
NKNExplorer.getSubscribers(topic, bucket);

(See more in Explorer API)

and some are for your convenience accessible directly from the wallet:

BigDecimal balance = wallet.queryBalance();