Skip to main content

Developer Guide

This section provides resources for developers building applications, smart contracts, and services on Shamwari Network.

Development Prerequisites

ToolVersionPurpose
Java21 LTSNode compilation
Maven/GradleLatestDependency management
Git2.40+Source control
Docker24+Containerized deployment

Project Structure

shamwariQKP/
├── src/java/nxt/
│ ├── http/ # REST API endpoints
│ ├── account/ # Account model and logic
│ ├── blockchain/ # Block and transaction processing
│ ├── crypto/ # Post-quantum cryptography
│ ├── ae/ # Asset exchange, Totems
│ ├── db/ # Database layer
│ ├── peer/ # P2P networking
│ ├── voting/ # Phasing and voting
│ ├── subscriptions/ # Subscription services
│ ├── addons/ # Smart contracts, WASM
│ └── util/ # Utilities
├── html/ # Web UI and API console
├── conf/ # Configuration files
└── dist/ # Compiled artifacts

Building

# Clean and compile
./compile.sh

# Run tests
./run-tests.sh

# Package distribution
./package.sh

API Development

Adding a New API Endpoint

  1. Create handler class extending APIServlet.APIRequestHandler
  2. Register in APIEnum.java
  3. Add parameter parsing in constructor
  4. Implement processRequest(HttpServletRequest)
  5. Return JSONStreamAware response

Example:

public final class MyNewApi extends APIServlet.APIRequestHandler {
static final MyNewApi instance = new MyNewApi();

private MyNewApi() {
super(new APITag[] {APITag.ACCOUNTS}, "account", "param1");
}

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
// ... implementation
return response;
}
}

API Tags

TagDescription
ACCOUNTSAccount-related queries
BLOCKSBlock and chain info
TRANSACTIONSTransaction operations
TOKENSTotem operations
MSMonetary System (currencies)
AEAsset Exchange
CONTRACTSSmart contracts
PHASINGTime-locked transactions
SHUFFLINGPrivacy shuffles
NETWORKPeer and networking
DEBUGAdmin/debug functions
UTILSUtility functions

Smart Contracts

Shamwari supports WASM-based smart contracts:

// Contract example
function transfer(amount, recipient) {
require(balance >= amount);
balance -= amount;
recipient.balance += amount;
}

See Smart Contracts for full details.

Testing

# Unit tests
mvn test

# Integration tests
mvn verify -P integration-tests

# API tests
./test-api.sh

Contribution Guidelines

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/my-feature
  3. Follow Java code style (Google Java Style Guide)
  4. Add tests for new functionality
  5. Update documentation
  6. Submit pull request

Debugging

Enable Debug Logging

nxt.debug=true
nxt.debugTrace=true

API Request Logging

tail -f logs/shamwari.log | grep "API request"

Database Inspection

# H2 console
java -cp "dist/*" org.h2.tools.Console

Resources