Skip to main content

Client Libraries

Shamwari ships with a built-in Java client library in the nxt.http package. There are no official TypeScript, Python, Go, or Rust client libraries maintained by the Shamwari project. All examples below use the Java client included in the shamwariQKP distribution.

Java Client Library​

The client library consists of:

PackageContents
nxt.http.APICallBase request builder with fluent API and in-process/remote connector support
nxt.http.callers.ApiSpecEnum of all API endpoints with their accepted parameters
nxt.http.callers.*CallAuto-generated typed callers (e.g., GetStateCall, SendCoinCall)
nxt.http.responses.*Typed response wrappers (TransactionResponse, BlockResponse, etc.)
nxt.addons.JOJSON object wrapper with convenience accessors
nxt.crypto.ShamwariQKPHybrid post-quantum key pair (Kyber + Dilithium)

Class Path Setup​

After compiling, include the node classes and dependencies on your classpath:

javac -cp classes:lib/*:conf AddOnExample.java
java -cp classes:lib/*:conf AddOnExample

Connecting to a Remote Node​

By default, APICall.Builder uses in-process execution (calling the API servlets directly). To connect to a remote node, set the remote URL:

import nxt.http.APICall;
import nxt.http.callers.*;

// Connect to a remote node
URL remoteUrl = new URL("http://localhost:22024/nxt");
JO state = new GetStateCall().remote(remoteUrl).includeCounts(true).call();

Basic Usage Patterns​

Read Blockchain Status​

JO state = new GetStateCall()
.includeCounts(true)
.adminPassword("your_admin_password")
.call();

System.out.println("Blocks: " + state.getLong("numberOfBlocks"));
System.out.println("Peers: " + state.getLong("numberOfPeers"));
System.out.println("Connected peers: " + state.getLong("numberOfConnectedPeers"));

Get Account Information​

JO account = new GetAccountCall()
.account("S-XXXX-XXXX-XXXX-XXXXX") // RS address
.includeLessors(true)
.includeTotems(true)
.includeCurrencies(true)
.includeEffectiveBalance(true)
.call();

System.out.println("Balance (FQT): " + account.getString("balanceFQT"));
System.out.println("Effective balance (FXT): " + account.getInt("effectiveBalanceFXT"));

Send Coins​

The SendCoinCall builder extends CreateTransactionCallBuilder, so it inherits all transaction parameters (deadline, broadcast, fees, etc.). The amount is specified in MTA (Shamari Token Amount), not NQT:

JO tx = new SendCoinCall(1) // chain ID 1 = BetaChain
.recipient("S-RECIPIENT-RS-ADDRESS")
.amountMTA(100000000L) // 1 MTA = 10^8 units
.secretPhrase("your_secret_phrase")
.broadcast(true)
.call();

System.out.println("Transaction: " + tx.getString("transactionFullHash"));

To get a typed TransactionResponse instead:

TransactionResponse tx = new SendCoinCall(1)
.recipient("recipient_RS")
.amountMTA(100000000L)
.secretPhrase("secret")
.broadcast(true)
.getCreatedTransaction();

Get a Transaction​

TransactionResponse tx = new GetTransactionCall()
.transactionFullHash("full_hash_hex")
.getTransaction();

List Blocks​

List<BlockResponse> blocks = new GetBlocksCall()
.firstIndex(0)
.lastIndex(9)
.includeTransactions(true)
.getBlocks();

blocks.forEach(block -> System.out.println("Height: " + block.getHeight()));

Post-Quantum Key Pair Usage​

Shamwari uses a hybrid Kyber-512 (key encapsulation) + Dilithium (signature) scheme. Use ShamwariQKP instead of raw secret phrases when possible:

import nxt.crypto.ShamwariQKP;
import nxt.crypto.Crypto;
import nxt.http.callers.GetShamwariQKPCall;

// Derive a key pair from a secret phrase
ShamwariQKP qkp = Crypto.getShamwariQKP("your secret phrase");

// Use the key pair for signing (auto-handled by APICall)
JO result = new GetShamwariQKPCall()
.shamwariPrivateKey(qkp.getPrivateKey().getCombinedPrivateKey())
.call();

System.out.println("Public key: " + result.getString("publicKey"));

// Clean up sensitive material
qkp.destroy();

The APICall.Builder accepts a shamwariQKP(ShamwariQKP) convenience method that sets both shamwariPrivateKey and shamwariPublicKey parameters automatically.

Response Handling​

The call() method returns a JO (JSON object). Common accessors:

MethodReturns
getString(key)String value
getInt(key)Integer value
getLong(key)Long value
getBoolean(key)Boolean value
getJo(key)Nested JO
getJoList(key)List of JO
isExist(key)Whether key exists
isError()Whether errorCode is present
JO response = new GetBlockchainStatusCall().call();
if (response.isError()) {
System.err.println("Error " + response.getInt("errorCode") + ": " + response.getString("errorDescription"));
} else {
System.out.println("Version: " + response.getString("version"));
}

Regenerating the Client Library​

The *Call and *Response classes are auto-generated from the Java API handler sources by the APICallGenerator tool:

./generateAPICalls.sh

This reads every *.java in src/java/nxt/http/ and emits:

  • src/java/nxt/http/callers/ApiSpec.java — parameter definitions for every endpoint
  • src/java/nxt/http/callers/*Call.java — one typed builder per endpoint
  • src/java/nxt/http/responses/*Response.java — interface + impl pairs for structured responses

After adding a new API handler and running ./compile.sh, run ./generateAPICalls.sh to regenerate these files so your client code gets typed access to the new endpoint.

API Conventions​

All *Call builders follow these conventions:

  1. Factory method: XXXCall.create() or XXXCall.create(chain) for chain-specific APIs.
  2. Fluent setters: Each parameter has a typed setter method.
  3. Execution: .call() returns JO; .getTransaction() / .getBlocks() / .getTransactions() return typed lists.
  4. Remote mode: .remote(new URL("http://host:port/nxt")) for HTTP calls to a remote node.
  5. Validation: Parameters are validated against ApiSpec; invalid parameters throw IllegalArgumentException.
  6. Sensitive params: secretPhrase, adminPassword, and key material are hidden from logs by APIInProcessConnector when sensitive param detection is enabled.

API Endpoint Overview​

Endpoints are identified by the requestType parameter. Each maps to a handler class registered in APIEnum.java and grouped by APITag. See the API Reference for the full list of endpoints organized by category.

CategoryExample Endpoints
AccountsgetAccount, leaseBalance, setAccountInfo, getBalance
TransactionssendCoin, sendMessage, broadcastTransaction, parseTransaction
ForgingstartForging, stopForging, getForging
NetworkgetPeers, addPeer, getMyInfo, managePeersNetworking
Debugshutdown, scan, popOff, trimDerivedTables, setLogging
UtilitiesgetConstants, getConfiguration, evaluateExpression, hash