Welcome! This guide will get you from zero to running tests locally in under 30 minutes.
- Prerequisites
- Quick Start
- Detailed Setup
- Running Tests
- Security
- Common Issues
- Testnet Setup
- Development Workflow
Install these tools with the exact versions specified:
| Tool | Version | Installation |
|---|---|---|
| Node.js | 18.x or 20.x | nodejs.org |
| Rust | 1.74+ | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
| Python | 3.10+ | python.org |
| PostgreSQL | 14+ | postgresql.org |
| Docker | 24+ (optional) | docker.com |
| Git | 2.40+ | git-scm.com |
node --version # Should show v18.x or v20.x
npm --version # Should show 9.x or 10.x
rustc --version # Should show 1.74 or higher
python3 --version # Should show 3.10 or higher
psql --version # Should show 14 or higher
docker --version # Should show 24 or higher (if using Docker)# Add WebAssembly target (required for Soroban contracts)
rustup target add wasm32-unknown-unknown
# Install Stellar CLI (for contract deployment)
cargo install --locked stellar-cli --version 21.0.0
# Verify installation
stellar --versionbrew install postgresql@16
brew services start postgresql@16
createdb carbonledgersudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo -u postgres createdb carbonledger
sudo -u postgres psql -c "CREATE USER carbonledger WITH PASSWORD 'changeme';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE carbonledger TO carbonledger;"Download and install from postgresql.org, then:
psql -U postgres
CREATE DATABASE carbonledger;
CREATE USER carbonledger WITH PASSWORD 'changeme';
GRANT ALL PRIVILEGES ON DATABASE carbonledger TO carbonledger;
\qgit clone https://github.com/YOUR_USERNAME/carbonledger.git
cd carbonledgercp .env.example .envEdit .env and set these minimum required values:
# Database
DATABASE_URL=postgresql://carbonledger:changeme@localhost:5432/carbonledger
POSTGRES_PASSWORD=changeme
# JWT (generate a random secret)
JWT_SECRET=your-super-secret-jwt-key-change-this
# Stellar Network
STELLAR_NETWORK=testnet
STELLAR_RPC_URL=https://soroban-testnet.stellar.org
STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org
NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
# Backend
PORT=3001
FRONTEND_URL=http://localhost:3000
# Redis (optional for local dev)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=# Backend
cd backend
npm install
cd ..
# Frontend
cd frontend
npm install
cd ..
# Oracle (Python)
cd oracle
pip3 install -r requirements.txt
cd ..
# Contracts (Rust)
cd contracts
cargo build --target wasm32-unknown-unknown --release
cd ..cd backend
npx prisma migrate dev
npx prisma generate
cd ..# Rust contract tests
cd contracts
cargo test
cd ..
# Backend tests
cd backend
npm test
cd ..
# Frontend tests
cd frontend
npm test
cd ..Expected time: 15-25 minutes ⏱️
cd backend
# Install dependencies
npm install
# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma migrate dev
# Seed database (optional)
npx prisma db seed
# Run tests
npm test
# Start development server (optional)
npm run start:devThe backend will be available at http://localhost:3001.
cd frontend
# Install dependencies
npm install
# Run tests
npm test
# Start development server (optional)
npm run devThe frontend will be available at http://localhost:3000.
cd contracts
# Build all contracts
cargo build --target wasm32-unknown-unknown --release
# Run all tests
cargo test
# Run tests for specific contract
cargo test -p carbon_registry
cargo test -p carbon_credit
cargo test -p carbon_marketplace
cargo test -p carbon_oracle
# Run tests with output
cargo test -- --nocapturecd oracle
# Create virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run oracle services (requires deployed contracts)
python3 verification_listener.py
python3 price_oracle.py
python3 satellite_monitor.py# From project root
./scripts/test-all.shcd contracts
# All contracts
cargo test
# Specific contract
cargo test -p carbon_registry # 7 tests
cargo test -p carbon_credit # 10 tests
cargo test -p carbon_marketplace # 7 tests
cargo test -p carbon_oracle # 6 tests
# With detailed output
cargo test -- --nocapture
# Run specific test
cargo test test_register_projectcd backend
# All tests
npm test
# Watch mode
npm test -- --watch
# Coverage
npm test -- --coverage
# Specific test file
npm test projects.service.spec.tscd frontend
# All tests
npm test
# Watch mode
npm test -- --watch
# Coverage
npm test -- --coveragecd backend
npm test projects.performance.spec.tsIf you discover a security vulnerability in CarbonLedger, do not open a public GitHub issue.
Please report privately to: security@carbonledger.io
Include:
- Affected component(s) (contract, backend, frontend, oracle)
- Description of the vulnerability and its impact
- Proof-of-concept or reproduction steps if available
- Your suggested severity (Critical / High / Medium / Low)
We will acknowledge receipt within 48 hours and aim to provide a full response within 7 days. Critical findings will be triaged within 24 hours.
For complete details, see SECURITY.md.
Solution (macOS):
xcode-select --installSolution (Linux):
sudo apt install build-essentialSolution (Windows): Install Visual Studio Build Tools
Solution:
rustup update
rustup target add wasm32-unknown-unknownSymptoms:
Error: connect ECONNREFUSED 127.0.0.1:5432
Solution (macOS):
brew services start postgresql@16Solution (Linux):
sudo systemctl start postgresql
sudo systemctl enable postgresqlSolution (Windows):
# Start PostgreSQL service from Services app
# Or run: net start postgresql-x64-16Symptoms:
Error: P1001: Can't reach database server
Solution:
Check your DATABASE_URL in .env:
# Verify PostgreSQL is running
psql -U carbonledger -d carbonledger -h localhost
# If password fails, reset it:
sudo -u postgres psql
ALTER USER carbonledger WITH PASSWORD 'changeme';
\qSolution:
# Update Rust first
rustup update
# Install with specific version
cargo install --locked stellar-cli --version 21.0.0 --force
# If still fails, try without lock file
cargo install stellar-cli --version 21.0.0Symptoms:
ModuleNotFoundError: No module named 'stellar_sdk'
Solution:
cd oracle
pip3 install --upgrade pip
pip3 install -r requirements.txt
# If using virtual environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtSolution:
cd frontend
rm -rf node_modules package-lock.json
npm install
npm run buildSymptoms:
Error: port 5432 already in use
Solution:
# Stop local PostgreSQL
brew services stop postgresql@16 # macOS
sudo systemctl stop postgresql # Linux
# Or change port in docker-compose.yml
ports:
- "5433:5432" # Use 5433 insteadSolution: This is expected for integration tests without deployed contracts. Unit tests should pass:
cd contracts
cargo test --lib # Run only unit tests# 1. Generate and fund testnet account
stellar keys generate alice --network testnet --fund
# 2. Deploy contracts
cd contracts
./scripts/deploy-testnet.sh
# 3. Update .env with contract IDsFor complete testnet setup including:
- Multiple faucet methods
- Freighter wallet setup
- Contract deployment and initialization
- Getting testnet USDC
- Testing contract interactions
- Troubleshooting testnet issues
See: Testnet Guide
git checkout -b feat/your-feature-nameEdit code, add tests, update documentation.
# Rust tests
cd contracts && cargo test
# Backend tests
cd backend && npm test
# Frontend tests
cd frontend && npm testFollow Conventional Commits:
git add .
git commit -m "feat: add serial number validation"
git commit -m "fix: resolve double-counting bug"
git commit -m "docs: update API documentation"git push origin feat/your-feature-nameThen create a Pull Request on GitHub.
- Use
snake_casefor functions and variables - Use
PascalCasefor types and enums - Add doc comments for public functions
- Use
CarbonErrorenum for all errors - Follow checks-effects-interactions pattern
/// Register a new carbon project
pub fn register_project(
env: Env,
project_id: String,
owner: Address,
) -> Result<(), CarbonError> {
// Checks
if project_exists(&env, &project_id) {
return Err(CarbonError::ProjectAlreadyExists);
}
// Effects
save_project(&env, &project_id, &owner);
// Interactions
emit_event(&env, "ProjectRegistered", project_id);
Ok(())
}- Use
camelCasefor variables and functions - Use
PascalCasefor components and classes - Add JSDoc comments for exported functions
- Use TypeScript strict mode
- Prefer
constoverlet
/**
* Retire carbon credits permanently on-chain
*/
export async function retireCredits(
batchId: string,
amount: number,
beneficiary: string
): Promise<RetirementCertificate> {
// Implementation
}- Follow PEP 8 style guide
- Use
snake_casefor functions and variables - Use
PascalCasefor classes - Add docstrings for functions
- Use type hints
def submit_monitoring_data(
project_id: str,
tonnes_verified: int,
methodology_score: int
) -> str:
"""
Submit monitoring data to oracle contract
Args:
project_id: Unique project identifier
tonnes_verified: Verified CO2 tonnes
methodology_score: Quality score (0-100)
Returns:
Transaction hash
"""
# Implementation- Documentation: Check docs/ folder
- Architecture Decisions: See docs/adr/
- API Reference: See backend/docs/PROJECTS_API.md
- Issues: GitHub Issues
- Discussions: GitHub Discussions
After completing this guide, you should be able to:
- ✅ Run all tests locally
- ✅ Deploy contracts to testnet
- ✅ Start the development servers
- ✅ Make code changes and test them
- ✅ Submit pull requests
Ready to contribute? Check out:
Welcome to the CarbonLedger community! 🌍