Developer Guide
This section provides resources for developers building applications, smart contracts, and services on Shamwari Network.
Development Prerequisites
| Tool | Version | Purpose |
|---|---|---|
| Java | 21 LTS | Node compilation |
| Maven/Gradle | Latest | Dependency management |
| Git | 2.40+ | Source control |
| Docker | 24+ | 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
- Create handler class extending
APIServlet.APIRequestHandler - Register in
APIEnum.java - Add parameter parsing in constructor
- Implement
processRequest(HttpServletRequest) - Return
JSONStreamAwareresponse
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
| Tag | Description |
|---|---|
| ACCOUNTS | Account-related queries |
| BLOCKS | Block and chain info |
| TRANSACTIONS | Transaction operations |
| TOKENS | Totem operations |
| MS | Monetary System (currencies) |
| AE | Asset Exchange |
| CONTRACTS | Smart contracts |
| PHASING | Time-locked transactions |
| SHUFFLING | Privacy shuffles |
| NETWORK | Peer and networking |
| DEBUG | Admin/debug functions |
| UTILS | Utility 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
- Fork the repository
- Create feature branch:
git checkout -b feature/my-feature - Follow Java code style (Google Java Style Guide)
- Add tests for new functionality
- Update documentation
- 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