← Back to Home

Coordinator API

Integration Documentation for Sparkle Trade Coordinators

API Version 1.0 | Status: Mainnet Validated

Architecture Update (v1.0.0)

Sparkle Protocol has evolved to a fully decentralized architecture.

Instead of a centralized coordinator server, v1.0.0 uses:

  • Nostr Relays: Orders published as NIP-15 product events
  • NIP-04 Encrypted DMs: Peer-to-peer trade negotiation
  • NIP-07 Browser Wallets: Secure signing via Alby, nos2x
  • Taproot Atomic Swaps: On-chain settlement without custody

Try the new Serverless Swap Interface

Source Code & SDK (Open Source)

The complete Sparkle Protocol implementation is open source under MIT license:

  • GitHub Repository: github.com/ProtocolSparkle/Sparkles-Protocol
  • TypeScript SDK: src/ directory - Core swap library with PSBT construction, Taproot scripts
  • Reference Coordinator: mainnet/ directory - Working implementation with LND integration
  • Test Suite: tests/ directory - Regtest scripts, mainnet validation proofs
  • Browser Client: js/sparkle-browser.js - Nostr-based serverless trading

Quick Start: git clone https://github.com/ProtocolSparkle/Sparkles-Protocol.git && npm install

View on GitHub | SDK Documentation | Coordinator Code

1. Overview (Legacy Coordinator Model)

This page documents the original coordinator API concept. A Sparkle coordinator is a service that facilitates Lightning/Spark-based Ordinal trades. The coordinator:

  1. Accepts a sparkle_checkout object
  2. Validates pricing and inscription ownership
  3. Generates Lightning/Spark invoice
  4. Monitors for payment completion
  5. Executes on-chain Ordinal transfer

Note: This documentation describes a legacy API specification. The current implementation uses decentralized Nostr-based coordination instead.

2. API Endpoints

2.1 POST /api/checkout/prepare

Initiates a Lightning/Spark checkout for an Ordinal inscription.

Request Body

{
  "p": "sparkle",
  "op": "checkout",
  "version": 1,
  "inscription_id": "abc123...i0",
  "collection_ref": "def456...i0",
  "buyer": {
    "ord_address": "bc1p...buyer...",
    "lightning_address": "buyer@example.com"
  },
  "network": "spark",
  "max_total_sats": 1500000,
  "pricing": {
    "seller_sats": 1400000,
    "creator_royalty_sats": 20000,
    "market_fee_sats": 30000,
    "estimated_l1_fee_sats": 50000
  },
  "market": {
    "id": "example.market",
    "name": "Example Market"
  },
  "expiry_block": 900000
}

Response

{
  "checkout_id": "chk_1234567890",
  "status": "pending_payment",
  "invoice": "lnbc15000000...",
  "expires_at": 1234567890,
  "payment_request": {
    "type": "spark",
    "lightning_address": "coordinator@example.com",
    "amount_sats": 1500000,
    "memo": "Darkita #1234 via Sparkle"
  }
}

Error Responses

StatusDescription
400Invalid checkout format or pricing mismatch
404Inscription not found or not listed for sale
409Inscription already sold or checkout in progress

2.2 POST /api/checkout/status

Retrieves the current status of an ongoing checkout.

Request Body

{
  "checkout_id": "chk_1234567890"
}

Response

{
  "checkout_id": "chk_1234567890",
  "status": "confirmed",
  "inscription_id": "abc123...i0",
  "payment": {
    "received_sats": 1500000,
    "confirmed_at": 1234567890
  },
  "transfer": {
    "txid": "fedcba987654321...",
    "vout": 0,
    "confirmations": 2
  }
}

Status Values

StatusDescription
pending_paymentAwaiting Lightning payment
paidPayment received, preparing transfer
broadcastTransfer transaction broadcast to network
confirmedTransfer confirmed on-chain
failedCheckout failed (includes reason)
expiredCheckout expired without payment

2.3 GET /api/health

Health check endpoint for monitoring.

Response

{
  "status": "ok",
  "version": "1.0.0",
  "network": "mainnet",
  "lightning": {
    "connected": true,
    "node_id": "03abc..."
  },
  "bitcoin": {
    "connected": true,
    "block_height": 900000
  }
}

3. Implementation Requirements

3.1 Validation

Coordinators MUST validate incoming checkout requests:

3.2 Lightning Integration

Coordinators MUST handle Lightning payments:

3.3 Ordinal Transfer

Coordinators MUST execute on-chain transfers:

3.4 Fee Distribution

Coordinators MUST distribute funds correctly:

4. Example Integration

// JavaScript Example

// 1. Prepare checkout
const checkout = {
  p: "sparkle",
  op: "checkout",
  version: 1,
  inscription_id: "abc123...i0",
  collection_ref: "def456...i0",
  buyer: {
    ord_address: "bc1p...buyer...",
    lightning_address: "alice@example.com"
  },
  network: "spark",
  max_total_sats: 1500000,
  pricing: {
    seller_sats: 1400000,
    creator_royalty_sats: 70000,
    market_fee_sats: 20000,
    estimated_l1_fee_sats: 10000
  }
};

// 2. Send to coordinator
const response = await fetch('/api/checkout/prepare', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(checkout)
});

const { checkout_id, invoice } = await response.json();

// 3. Poll for status
const checkStatus = async () => {
  const status = await fetch('/api/checkout/status', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ checkout_id })
  });

  const result = await status.json();

  if (result.status === 'confirmed') {
    console.log('Transfer complete:', result.transfer.txid);
  } else if (result.status !== 'failed') {
    setTimeout(checkStatus, 5000);
  }
};

checkStatus();

5. Deployment Guide

Recommended: Serverless Nostr-Based Trading

The v1.0.0 architecture eliminates the need for a centralized coordinator. Trades are coordinated peer-to-peer using Nostr relays.

5.1 Serverless Setup (Recommended)

No server deployment required. Users connect directly via the Swap Interface.

  1. Install a Nostr browser extension: Alby, nos2x, or similar NIP-07 compatible wallet
  2. Install a Bitcoin wallet: Unisat, Xverse, or similar for PSBT signing
  3. Connect to relays: Default relays are pre-configured, or add custom relays
  4. Start trading: List inscriptions or browse available offers

5.2 Self-Hosted Coordinator (Advanced)

For marketplaces or high-volume traders who want dedicated infrastructure.

Prerequisites

Installation

# Clone the SDK repository
git clone https://github.com/ProtocolSparkle/Sparkles-Protocol.git
cd Sparkles-Protocol

# Install dependencies
npm install

# Configure environment
cp .env.example .env
# Edit .env with your LND credentials and Bitcoin RPC

# Run coordinator service
npm run coordinator

Configuration

# .env configuration
LND_MACAROON_PATH=/path/to/admin.macaroon
LND_CERT_PATH=/path/to/tls.cert
LND_HOST=localhost:10009

BITCOIN_RPC_HOST=localhost
BITCOIN_RPC_PORT=8332
BITCOIN_RPC_USER=your_user
BITCOIN_RPC_PASS=your_password

# Coordinator settings
COORDINATOR_FEE_SATS=1000
MIN_LOCKTIME_BLOCKS=6
MAX_TRADE_AMOUNT_SATS=10000000

Security Considerations

Note: Self-hosted coordinators are optional. The serverless Nostr-based approach provides the same security guarantees without infrastructure overhead.

6. Coordinator Trust Model

What the Coordinator CANNOT Do

  • Steal funds: The atomic swap ensures both parties are satisfied or the trade reverts
  • Steal inscriptions: Inscriptions are locked in Taproot scripts controlled by buyer/seller keys
  • Forge transactions: All signatures require private keys held only by the trading parties
  • Modify payment amounts: Lightning invoices are cryptographically bound to the swap

What the Coordinator CAN Do (Trust Assumptions)

  • Censor trades: A malicious coordinator can refuse to relay messages or match orders
  • Delay settlement: The coordinator could delay relaying payment confirmations
  • Front-run orders: A coordinator with trading interest could see orders before others
  • Collect metadata: IP addresses, trade patterns, and timing information may be logged

Mitigations

Bottom line: The coordinator facilitates trades but cannot steal. This is similar to how a Bitcoin mempool relayer can censor but not forge transactions. For maximum trustlessness, use the serverless Nostr-based swap interface.