The Apex SDK CLI is a powerful command-line tool for building, testing, and deploying blockchain applications across Substrate and EVM ecosystems.
git clone https://github.com/kherldhussein/apex-sdk.git
cd apex-sdk/cli
cargo install --path .
cargo install apex-sdk-cli
apex version
# Create a new project with the default template
apex new my-project
# Create a DeFi project
apex new defi-app --template defi
# Create an NFT project
apex new nft-marketplace --template nft
# Initialize with default settings
apex init
# Initialize with interactive prompts
apex init --interactive
This creates a .apex/config.json file in your project directory with default settings:
{
"default_chain": "polkadot",
"default_endpoint": "wss://polkadot.api.onfinality.io/public-ws",
"accounts": []
}
apex newCreate a new Apex SDK project from a template.
Usage:
apex new <PROJECT_NAME> [OPTIONS]
Options:
-t, --template <TEMPLATE>: Project template (default, defi, nft) [default: default]Examples:
# Basic project
apex new my-app
# DeFi application
apex new defi-protocol --template defi
# NFT marketplace
apex new nft-market --template nft
apex buildBuild your project using Cargo.
Usage:
apex build [OPTIONS]
Options:
-r, --release: Build in release mode with optimizationsExamples:
# Development build
apex build
# Production build
apex build --release
apex testRun your project’s test suite.
Usage:
apex test [OPTIONS]
Options:
-f, --filter <PATTERN>: Run only tests matching the patternExamples:
# Run all tests
apex test
# Run specific tests
apex test --filter substrate
apex test --filter evm_integration
apex benchRun performance benchmarks.
Usage:
apex bench [OPTIONS]
Options:
-f, --filter <PATTERN>: Run only benchmarks matching the patternExamples:
# Run all benchmarks
apex bench
# Run specific benchmarks
apex bench --filter transaction
apex account generateGenerate a new blockchain account/wallet.
Usage:
apex account generate [OPTIONS]
Options:
-a, --account-type <TYPE>: Account type (substrate, evm)Examples:
# Generate Substrate account
apex account generate --account-type substrate
# Generate EVM account
apex account generate --account-type evm
Output:
Generating new substrate account...
Type: Substrate (SR25519)
Address: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
Mnemonic: [SECURE - Store this safely!]
WARNING: Keep your keys secure and never share them!
apex account importImport an account from a mnemonic phrase.
Usage:
apex account import <MNEMONIC> [OPTIONS]
Options:
-a, --account-type <TYPE>: Account type (substrate, evm)Examples:
apex account import "word1 word2 ... word12" --account-type substrate
apex account import "word1 word2 ... word12" --account-type evm
apex account listList all managed accounts.
Usage:
apex account list
apex account balanceCheck the balance of an account.
Usage:
apex account balance <ADDRESS> [OPTIONS]
Options:
-c, --chain <CHAIN>: Chain name-e, --endpoint <ENDPOINT>: RPC endpoint URLExamples:
# Check Polkadot balance
apex account balance 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
--chain polkadot \
--endpoint wss://polkadot.api.onfinality.io/public-ws
# Check Ethereum balance
apex account balance 0x1234567890123456789012345678901234567890 \
--chain ethereum \
--endpoint https://mainnet.infura.io/v3/YOUR_KEY
apex chain listList all supported blockchain networks.
Usage:
apex chain list
Output:
Supported chains:
Substrate-based:
• polkadot - Polkadot Relay Chain
• kusama - Kusama Relay Chain
• moonbeam - Moonbeam Parachain
• astar - Astar Parachain
• acala - Acala DeFi Hub
• phala - Phala Privacy Cloud
• bifrost - Bifrost Liquid Staking
EVM-compatible:
• ethereum - Ethereum Mainnet
• bsc - Binance Smart Chain
• polygon - Polygon (Matic)
• avalanche - Avalanche C-Chain
• arbitrum - Arbitrum One (L2)
• optimism - Optimism (L2)
• zksync - zkSync Era (L2)
apex chain infoGet information about a specific chain.
Usage:
apex chain info <CHAIN> [OPTIONS]
Options:
-e, --endpoint <ENDPOINT>: RPC endpoint URLExamples:
apex chain info polkadot \
--endpoint wss://polkadot.api.onfinality.io/public-ws
apex chain info ethereum \
--endpoint https://mainnet.infura.io/v3/YOUR_KEY
apex chain healthCheck the health status of a chain endpoint.
Usage:
apex chain health <ENDPOINT>
Examples:
apex chain health wss://polkadot.api.onfinality.io/public-ws
apex chain health https://mainnet.infura.io/v3/YOUR_KEY
apex deployDeploy a smart contract to a blockchain.
Usage:
apex deploy <CONTRACT> [OPTIONS]
Options:
-c, --chain <CHAIN>: Target chain name-e, --endpoint <ENDPOINT>: RPC endpoint URLExamples:
# Deploy to Polkadot
apex deploy ./contracts/my_contract.wasm \
--chain polkadot \
--endpoint wss://polkadot.api.onfinality.io/public-ws
# Deploy to Ethereum
apex deploy ./contracts/MyContract.sol \
--chain ethereum \
--endpoint https://mainnet.infura.io/v3/YOUR_KEY
See Project Management section for apex test and apex bench commands.
The CLI stores configuration in .apex/config.json:
{
"default_chain": "polkadot",
"default_endpoint": "wss://polkadot.api.onfinality.io/public-ws",
"accounts": [
{
"type": "substrate",
"address": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"name": "Alice"
}
],
"custom_endpoints": {
"polkadot": [
"wss://polkadot.api.onfinality.io/public-ws",
"wss://rpc.polkadot.io"
],
"ethereum": [
"https://mainnet.infura.io/v3/YOUR_KEY"
]
}
}
You can override configuration using environment variables:
APEX_DEFAULT_CHAIN: Default blockchain to useAPEX_DEFAULT_ENDPOINT: Default RPC endpointAPEX_CONFIG_PATH: Path to configuration fileExample:
export APEX_DEFAULT_CHAIN=ethereum
export APEX_DEFAULT_ENDPOINT=https://mainnet.infura.io/v3/YOUR_KEY
apex chain info ethereum
# 1. Create a new DeFi project
apex new defi-protocol --template defi
# 2. Navigate to project
cd defi-protocol
# 3. Initialize configuration
apex init
# 4. Generate deployment account
apex account generate --account-type substrate
# 5. Build the project
apex build --release
# 6. Run tests
apex test
# 7. Run benchmarks
apex bench
# 8. Deploy to testnet
apex deploy ./target/release/defi_protocol.wasm \
--chain westend \
--endpoint wss://westend-rpc.polkadot.io
# 1. Check balance on Polkadot
apex account balance 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
--chain polkadot \
--endpoint wss://polkadot.api.onfinality.io/public-ws
# 2. Check health of destination chain
apex chain health wss://moonbeam.api.onfinality.io/public-ws
# 3. Get chain information
apex chain info moonbeam \
--endpoint wss://moonbeam.api.onfinality.io/public-ws
# Create project
apex new multi-chain-app
cd multi-chain-app
# List all supported chains
apex chain list
# Test on multiple chains
apex test --filter substrate
apex test --filter evm
# Build optimized release
apex build --release
# Run benchmarks
apex bench
Problem: Build fails with dependency errors
Solution:
# Clean and rebuild
cargo clean
apex build
# Update dependencies
cargo update
apex build --release
Problem: Cannot connect to RPC endpoint
Solution:
# Check endpoint health first
apex chain health <ENDPOINT>
# Verify endpoint is correct
apex chain info <CHAIN> --endpoint <ENDPOINT>
# Try alternative endpoint
apex chain list # Shows alternative endpoints
Problem: Account generation fails
Solution:
# Ensure you have latest version
apex version
# Try with explicit account type
apex account generate --account-type substrate
# General help
apex --help
# Command-specific help
apex new --help
apex deploy --help
apex account --help
For debugging, set the RUST_LOG environment variable:
# Info level
RUST_LOG=info apex build
# Debug level
RUST_LOG=debug apex deploy ./contract.wasm --chain polkadot --endpoint wss://...
# Trace level (very verbose)
RUST_LOG=trace apex test
You can create custom project templates by adding them to the cli/templates directory:
# Use custom template
apex new my-app --template custom
The CLI is designed to work well in scripts:
#!/bin/bash
set -e
# Automated deployment script
apex build --release
apex test
apex deploy ./target/release/app.wasm \
--chain polkadot \
--endpoint $POLKADOT_ENDPOINT
# Check deployment
apex chain info polkadot --endpoint $POLKADOT_ENDPOINT
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Install Apex CLI
run: cargo install apex-sdk-cli
- name: Build
run: apex build --release
- name: Test
run: apex test
- name: Deploy
run: |
apex deploy ./target/release/app.wasm \
--chain polkadot \
--endpoint $
Apache-2.0 - See LICENSE for details.