← Back to Home

Sparkle Protocol: Practical Implementation Guide

You are in the Implementation Track – production guides and developer resources.

Status: Mainnet Validated

  • Production Ready: Core protocol validated on Bitcoin mainnet
  • SDK Available: TypeScript SDK with safety gates
  • Coordinator: Reference implementation available
  • Testing recommended: Start on testnet before mainnet

Implementation Guide

Version 1.0.0 | December 2025

For Developers & Testers

Overview

This guide provides step-by-step instructions for testing Sparkle Protocol on Bitcoin testnet. It covers setting up a Lightning node, creating Sparkle-compatible inscriptions, and understanding the proposed trading flow.

Note: This guide covers setup for both testnet and mainnet. We recommend integration testing on testnet first before deploying to mainnet. The protocol has been validated on mainnet with comprehensive testing.

1. Prerequisites

1.1 Required Software

Before implementing Sparkle Protocol, you'll need:

1.2 Estimated Setup Time

Note: This guide assumes basic familiarity with Bitcoin, Lightning Network, and command line tools.

2. Bitcoin Core Setup (Testnet)

2.1 Install Bitcoin Core

# Download from bitcoin.org
wget https://bitcoincore.org/bin/bitcoin-core-25.0/bitcoin-25.0-x86_64-linux-gnu.tar.gz

# Extract and install
tar -xzf bitcoin-25.0-x86_64-linux-gnu.tar.gz
sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-25.0/bin/*

2.2 Configure for Testnet

Create ~/.bitcoin/bitcoin.conf:

# Testnet Configuration
testnet=1
server=1
txindex=1

# RPC Settings
rpcuser=your_rpc_username
rpcpassword=your_secure_password
rpcport=18332

# Optional: Prune if disk space limited
# prune=550

2.3 Start Bitcoin Core

# Start testnet node
bitcoind -testnet -daemon

# Check sync status
bitcoin-cli -testnet getblockchaininfo

# Get testnet coins from faucet
# Visit: https://testnet-faucet.mempool.co

3. Lightning Network Setup

3.1 Install LND

# Download LND
wget https://github.com/lightningnetwork/lnd/releases/download/v0.17.0-beta/lnd-linux-amd64-v0.17.0-beta.tar.gz

# Extract
tar -xzf lnd-linux-amd64-v0.17.0-beta.tar.gz

# Install
sudo install -m 0755 -o root -g root -t /usr/local/bin lnd-linux-amd64-v0.17.0-beta/*

3.2 Configure LND

Create ~/.lnd/lnd.conf:

# LND Testnet Configuration
[Application Options]
debuglevel=info
maxpendingchannels=10

[Bitcoin]
bitcoin.active=1
bitcoin.testnet=1
bitcoin.node=bitcoind

[Bitcoind]
bitcoind.rpcuser=your_rpc_username
bitcoind.rpcpass=your_secure_password
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

3.3 Start LND

# Start LND
lnd

# Create wallet (separate terminal)
lncli create

# Get testnet Lightning address
lncli newaddress p2wkh

# Fund your Lightning wallet with testnet BTC
bitcoin-cli -testnet sendtoaddress YOUR_LND_ADDRESS 0.01

# Wait for confirmation, then open channel
lncli openchannel --node_key NODE_PUBKEY --local_amt 1000000

4. Ord Installation & Setup

4.1 Install Ord

# Install via cargo (Rust required)
cargo install ord

# Or download binary
wget https://github.com/ordinals/ord/releases/download/0.14.0/ord-0.14.0-x86_64-unknown-linux-gnu.tar.gz
tar -xzf ord-0.14.0-x86_64-unknown-linux-gnu.tar.gz
sudo install -m 0755 ord /usr/local/bin/

4.2 Configure Ord for Testnet

# Set testnet mode
export ORD_BITCOIN_RPC_URL=http://localhost:18332
export ORD_BITCOIN_RPC_USERNAME=your_rpc_username
export ORD_BITCOIN_RPC_PASSWORD=your_secure_password

# Create ord wallet
ord --testnet wallet create

# Get receiving address
ord --testnet wallet receive

5. Creating Sparkle-Compatible Inscriptions

5.1 Sparkle Metadata Format

Create sparkle-nft.json:

{
  "p": "sparkle",
  "v": 1,
  "nft": {
    "name": "Test Sparkle NFT",
    "description": "Sparkle Protocol mainnet inscription example"
  },
  "lightning": {
    "enabled": true,
    "min_channel_capacity": 100000
  },
  "trade": {
    "fee_rate": 1
  }
}

5.2 Inscribe to Testnet

# Inscribe the metadata
ord --testnet wallet inscribe --file sparkle-nft.json --fee-rate 10

# Note the inscription ID from output
# Example: abc123def456...i0

# Check inscription
ord --testnet wallet inscriptions
Note: The inscription ID is critical—this marks the NFT as Sparkle-compatible. Marketplaces would detect this metadata to enable Lightning trading.

5.3 Multi-File Inscriptions

For NFTs with artwork + metadata:

# 1. Inscribe artwork first
ord --testnet wallet inscribe --file artwork.png --fee-rate 10
# Output: artwork_inscription_id

# 2. Inscribe Sparkle metadata referencing artwork
# Create sparkle-with-parent.json:
{
  "p": "sparkle",
  "v": 1,
  "parent": "artwork_inscription_id",
  "nft": {
    "name": "Artwork with Sparkle",
    "image": "/content/artwork_inscription_id"
  },
  "lightning": {
    "enabled": true
  }
}

# Inscribe metadata
ord --testnet wallet inscribe --file sparkle-with-parent.json --fee-rate 10

6. Understanding the Trading Flow

6.1 Conceptual Trade Example

Here's how a Sparkle trade would work (coordinator required):

Scenario: Alice wants to sell inscription abc123 to Bob for 100,000 sats via Lightning.

Step 1: Trade Initiation

# Alice lists inscription for sale
# (Via SDK or marketplace integration)
{
  "inscription_id": "abc123...i0",
  "price_sats": 100000,
  "seller_lightning_node": "03alice..."
}

Step 2: HTLC Creation

# Coordinator generates payment hash
preimage = randomBytes(32)
payment_hash = sha256(preimage)

# Create Lightning invoice
lncli addinvoice --amt 100000 --memo "Sparkle trade abc123" --hash payment_hash

Step 3: PSBT Preparation

# Alice creates PSBT transferring inscription to Bob
bitcoin-cli -testnet createpsbt \
  '[{"txid":"alice_utxo_txid","vout":0}]' \
  '[{"bob_address":0.00000546}]'

# Alice signs PSBT
bitcoin-cli -testnet signrawtransactionwithwallet PSBT_HEX

Step 4: Atomic Settlement

# Bob pays Lightning invoice
lncli payinvoice INVOICE_STRING

# Coordinator receives payment (locked by hash)
# Coordinator broadcasts PSBT
bitcoin-cli -testnet sendrawtransaction SIGNED_PSBT_HEX

# Coordinator reveals preimage to claim Lightning payment
# Trade complete: Bob gets inscription, Alice gets sats
Note: This flow demonstrates the conceptual trade sequence. A reference coordinator implementation is available in the SDK. Production deployments should implement proper timeout handling and error recovery.

7. Coordinator Development (Future)

7.1 Coordinator Responsibilities

A Sparkle coordinator would need to:

7.2 Basic Coordinator Pseudocode

class SparkleCoordinator {
  async createTrade(inscription_id, price, seller, buyer) {
    // Generate preimage and hash
    const preimage = randomBytes(32)
    const hash = sha256(preimage)

    // Create Lightning invoice
    const invoice = await this.createInvoice(price, hash)

    // Request PSBT from seller
    const psbt = await this.requestPSBT(seller, inscription_id, buyer)

    // Store trade state
    this.trades[hash] = {
      preimage,
      psbt,
      inscription_id,
      status: 'pending'
    }

    return invoice
  }

  async onPaymentReceived(payment_hash) {
    const trade = this.trades[payment_hash]

    // Broadcast PSBT
    await this.broadcastPSBT(trade.psbt)

    // Reveal preimage to claim payment
    await this.claimPayment(trade.preimage)

    trade.status = 'complete'
  }
}
Note: Actual coordinator implementation requires robust error handling, timeout management, and security measures not shown here.

8. Testing & Verification

8.1 Verify Inscription Metadata

# Check inscription content
ord --testnet wallet inscription INSCRIPTION_ID

# Verify Sparkle metadata is present
# Should contain: "p": "sparkle"

8.2 Test Lightning Payments

# Create test invoice
lncli addinvoice --amt 1000 --memo "Test payment"

# Pay invoice (from another node or testnet wallet)
lncli payinvoice PAYMENT_REQUEST

# Verify payment
lncli listinvoices

8.3 Verify Bitcoin Transactions

# Create and broadcast PSBT manually
bitcoin-cli -testnet createpsbt ...
bitcoin-cli -testnet signrawtransactionwithwallet ...
bitcoin-cli -testnet sendrawtransaction ...

# Check transaction status
bitcoin-cli -testnet gettransaction TXID

9. Common Issues & Solutions

9.1 Bitcoin Core Issues

Problem: "Cannot connect to Bitcoin Core"

# Solution: Check Bitcoin Core is running
bitcoin-cli -testnet getblockchaininfo

# Verify RPC credentials in bitcoin.conf

9.2 Lightning Network Issues

Problem: "Insufficient channel capacity"

# Solution: Open larger channel or multiple channels
lncli openchannel --node_key PUBKEY --local_amt 5000000

# Check current channels
lncli listchannels

9.3 Ord Issues

Problem: "Insufficient funds for inscription"

# Solution: Fund ord wallet
bitcoin-cli -testnet sendtoaddress ORD_ADDRESS 0.001

# Check ord wallet balance
ord --testnet wallet balance

10. Next Steps

10.1 For Developers

10.2 For Researchers

10.3 For Users

Note: Sparkle Protocol has been validated on Bitcoin mainnet. Always test on testnet first before deploying production applications.

10.5 Fee and Timelock Guidance

Proper fee and timelock configuration is critical for successful atomic swaps. The following recommendations are based on mainnet testing.

Timelock Recommendations

ParameterRecommended ValueRationale
Minimum Timelock 6 blocks (~1 hour) Allows time for buyer to claim after preimage revelation
Recommended Timelock 12-24 blocks (2-4 hours) Provides safety margin for fee bumping and network delays
Lightning HTLC Expiry 2x on-chain timelock HTLC should expire AFTER the on-chain timelock to ensure atomicity

Fee Recommendations

TransactionRecommended Fee RateNotes
Lock TX Current mempool median + 20% Should confirm within 1-2 blocks to start the swap
Claim TX (Buyer) High priority (next block) Must confirm before timelock expires; use 50+ sat/vB during congestion
Refund TX (Seller) Medium priority Only used if buyer fails to claim; can wait for lower fees

Fee Spike Mitigation

Example Numeric Values

# Typical swap configuration (December 2025)
Lock TX Fee Rate:    15-25 sat/vB (normal conditions)
Claim TX Fee Rate:   30-50 sat/vB (priority)
Refund TX Fee Rate:  10-15 sat/vB (can wait)

# Transaction sizes
Lock TX:   ~150 vbytes
Claim TX:  ~142 vbytes (script-path spend)
Refund TX: ~138 vbytes

# Total fees (at 20 sat/vB average)
Lock:   ~3,000 sats
Claim:  ~2,840 sats
Total:  ~5,840 sats per swap
    
Warning: During high-fee periods (100+ sat/vB), consider delaying non-urgent swaps. Always ensure you have sufficient funds for fee bumping before initiating a swap.

11. Additional Resources

11.1 Testnet Faucets

11.2 Documentation

11.3 Community