| Crates.io | cargo-polkajam |
| lib.rs | cargo-polkajam |
| version | 0.1.1 |
| created_at | 2025-12-29 21:17:20.076992+00 |
| updated_at | 2025-12-29 22:01:10.445714+00 |
| description | A cargo subcommand for generating JAM service projects for Polkadot |
| homepage | |
| repository | https://github.com/abutlabs/cargo-polkajam |
| max_upload_size | |
| id | 2011457 |
| size | 260,243 |
cargo, make me a JAM service
A Rust cargo subcommand for generating and building JAM (Join-Accumulate Machine) services for Polkadot. Follows the cargo-generate project architecture while providing JAM-specific tooling.
cargo install cargo-polkajam
git clone https://github.com/abutlabs/cargo-polkajam
cd cargo-polkajam
cargo install --path .
To reinstall after making changes:
cargo install --path . --force
Before using cargo-polkajam, you need:
cargo install jam-pvm-build
# 1. Install the JAM toolchain (downloads polkajam binaries)
cargo polkajam setup
# 2. Create a new JAM service
cargo polkajam new my-service
# 3. Build the service
cd my-service
cargo polkajam build
# 4. Start local testnet
cargo polkajam up
# 5. Deploy to testnet (in another terminal)
cargo polkajam deploy my-service.jam
# 6. Stop testnet when done
cargo polkajam down
cargo polkajam setupDownloads and installs the JAM/polkajam toolchain from polkajam-releases.
# Install latest nightly
cargo polkajam setup
# List available versions
cargo polkajam setup --list
# Show installed toolchain info
cargo polkajam setup --info
# Install specific version
cargo polkajam setup --version nightly-2025-12-29
# Force reinstall
cargo polkajam setup --force
# Update to latest
cargo polkajam setup --update
Installed binaries (in ~/.cargo-polkajam/toolchain/polkajam-nightly/):
polkajam - JAM nodejamt - JAM CLI tool for deploymentpolkajam-testnet - Local testnet runnerpolkajam-repl - Interactive REPLcorevm-builder - CoreVM buildercargo polkajam newCreates a new JAM service project from a template.
# Interactive mode
cargo polkajam new my-service
# Skip prompts, use defaults
cargo polkajam new my-service --defaults
# Use custom git template
cargo polkajam new my-service --git https://github.com/user/template
# Specify template values
cargo polkajam new my-service -d author="Your Name" -d license=MIT
Options:
-t, --template <name> - Template name (default: basic-service)--git <url> - Git repository URL for custom template--branch <branch> - Git branch (requires --git)--path <path> - Subdirectory in git repo (requires --git)-o, --output <dir> - Output directory--defaults - Skip prompts, use defaults-d, --define <key=value> - Set template variable--no-git - Don't initialize git repositorycargo polkajam buildBuilds a JAM service into a .jam blob using jam-pvm-build.
# Build in release mode (default)
cargo polkajam build
# Build specific project
cargo polkajam build --path /path/to/service
# Custom output path
cargo polkajam build --output my-service.jam
# Verbose output
cargo polkajam build --verbose
Options:
-p, --path <dir> - Project path (default: current directory)--release - Build in release mode (default: true)-o, --output <path> - Output path for .jam blob-v, --verbose - Verbose outputcargo polkajam upStarts the local JAM testnet.
# Start in background (default)
cargo polkajam up
# Start in foreground (see logs)
cargo polkajam up --foreground
# Custom RPC endpoint
cargo polkajam up --rpc ws://localhost:9944
Options:
--foreground - Run in foreground (see logs, Ctrl+C to stop)--rpc <url> - RPC endpoint (default: ws://localhost:19800)-v, --verbose - Verbose outputcargo polkajam downStops the local JAM testnet.
# Stop the testnet gracefully
cargo polkajam down
# Force kill
cargo polkajam down --force
Options:
--force - Force kill with SIGKILL instead of SIGTERM-v, --verbose - Verbose outputcargo polkajam deployDeploys a JAM service to the network.
# Deploy a service
cargo polkajam deploy my-service.jam
# Deploy with initial balance
cargo polkajam deploy my-service.jam --amount 1000
# Deploy with memo
cargo polkajam deploy my-service.jam --memo "my memo data"
# Deploy to custom RPC endpoint
cargo polkajam deploy my-service.jam --rpc ws://localhost:9944
# Register service with a name
cargo polkajam deploy my-service.jam --register my_service
Options:
--amount <value> - Initial balance for the service (default: 0)--memo <data> - Memo data to include-G, --min-item-gas <value> - Minimum gas per work item (default: 1000000)-g, --min-memo-gas <value> - Minimum gas for memo (default: 1000000)-r, --register <name> - Register service with a name--rpc <url> - RPC endpoint (default: ws://localhost:19800)-v, --verbose - Verbose outputcargo polkajam monitorMonitor the testnet with an interactive TUI (jamtop).
# Start the monitor
cargo polkajam monitor
# Monitor with custom RPC endpoint
cargo polkajam monitor --rpc ws://localhost:9944
Options:
--rpc <url> - RPC endpoint (default: ws://localhost:19800)-v, --verbose - Verbose outputcargo polkajam testRun comprehensive end-to-end tests that verify the entire workflow.
# Run full test suite
cargo polkajam test
# Run tests with verbose output
cargo polkajam test --verbose
# Keep testnet running after tests (for debugging)
cargo polkajam test --keep-running
# Skip testnet startup (use already running testnet)
cargo polkajam test --skip-testnet
# Use custom test directory
cargo polkajam test --dir /tmp/my-test
Options:
--keep-running - Keep testnet running after tests complete--skip-testnet - Skip testnet startup (assume already running)--dir <path> - Test directory (default: temp directory)-v, --verbose - Verbose output with command detailsTests performed:
cargo polkajam new).jam blob (cargo polkajam build)# Run commands directly
cargo run -- setup --info
cargo run -- new test-service --defaults
cargo run -- build
# Or build and install locally
cargo build && cargo install --path . --force
# Make changes, rebuild, and test
cargo build && cargo install --path . --force && cargo polkajam setup --info
cargo uninstall cargo-polkajam
rm -rf ~/.cargo-polkajam # Remove toolchain and config
# Terminal 1: Start the testnet
cargo polkajam up --foreground
# Terminal 2: Create and deploy a service
cargo polkajam new test-service --defaults
cd test-service
cargo polkajam build
cargo polkajam deploy test-service.jam
# Stop the testnet when done
cargo polkajam down
# Start testnet in background
cargo polkajam up
# Create, build, and deploy
cargo polkajam new test-service --defaults
cd test-service
cargo polkajam build
cargo polkajam deploy test-service.jam
# Stop testnet
cargo polkajam down
# Monitor with jamtop
cargo polkajam monitor
# Interactive REPL
~/.cargo-polkajam/toolchain/polkajam-nightly/polkajam-repl
Generated JAM service structure:
my-service/
├── Cargo.toml # Dependencies: jam-pvm-common, polkavm-derive
├── src/
│ └── lib.rs # Service implementation (refine, accumulate)
└── .gitignore
#![no_std]
#![no_main]
extern crate alloc;
use jam_pvm_common::{declare_service, Service, accumulate::*, jam_types::*};
declare_service!(MyService);
struct MyService;
impl Service for MyService {
fn refine(
_core_index: CoreIndex,
_item_index: usize,
_service_id: ServiceId,
payload: WorkPayload,
_package_hash: WorkPackageHash,
) -> WorkOutput {
// Stateless computation (up to 6 seconds)
payload.take().into()
}
fn accumulate(
_slot: Slot,
_service_id: ServiceId,
item_count: usize,
) -> Option<Hash> {
// Stateful integration (~10ms)
None
}
}
Configuration is stored in ~/.cargo-polkajam/:
~/.cargo-polkajam/
├── config.toml # Toolchain configuration
└── toolchain/
└── polkajam-nightly/ # Installed binaries
config.toml:
installed_version = "nightly-2025-12-29"
toolchain_path = "/Users/you/.cargo-polkajam/toolchain"
installed_at = "1767015039"
The easiest way to test the entire cargo-polkajam workflow:
# Run full end-to-end test suite
cargo polkajam test
# Run with verbose output
cargo polkajam test --verbose
This automatically tests: new → build → up → deploy → down
# Run all Rust tests (excluding ignored tests)
cargo test
# Run with verbose output
cargo test -- --nocapture
# Run ignored tests that require toolchain
cargo test --test integration_tests -- --ignored
These tests require a running local testnet:
# Terminal 1: Start the testnet
cargo polkajam up --foreground
# Terminal 2: Run testnet tests
cargo test --test testnet_tests -- --ignored --nocapture
The testnet tests will:
.jam blobcargo polkajam deployThis repo has CI/CD that automatically publishes to crates.io when you create a version tag:
One-time setup:
CARGO_REGISTRY_TOKENTo release a new version:
# Update version in Cargo.toml
# Commit changes
git add . && git commit -m "Release v0.1.0"
# Create and push a version tag
git tag v0.1.0
git push origin main --tags
This triggers the release workflow which:
# Login to crates.io
cargo login <your-token>
# Dry run to verify
cargo publish --dry-run
# Publish
cargo publish
MIT OR Apache-2.0