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.
1. Prerequisites
1.1 Required Software
Before implementing Sparkle Protocol, you'll need:
- Bitcoin Core: Testnet full node (v25.0+)
- Lightning Network Node: LND (v0.17+) or Core Lightning (v23.11+)
- Ord: Ordinals inscription tool (v0.14.0+)
- Node.js: v18+ (for coordinator/SDK development)
- Testnet Bitcoin: From a faucet
1.2 Estimated Setup Time
- Bitcoin Core sync (testnet): 2-4 hours
- Lightning node setup: 1-2 hours
- Ord installation: 15 minutes
- First inscription: 30 minutes
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
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):
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
7. Coordinator Development (Future)
7.1 Coordinator Responsibilities
A Sparkle coordinator would need to:
- Accept trade requests from buyers and sellers
- Create HTLCs with appropriate timeouts
- Verify PSBT signatures and UTXO availability
- Broadcast PSBTs when Lightning payments succeed
- Handle timeout scenarios gracefully
- Monitor blockchain confirmations
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'
}
}
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
- Review the SDK documentation
- Study technical analysis
- Experiment with testnet inscriptions
- Build proof-of-concept coordinator
- Provide feedback on specification
10.2 For Researchers
- Analyze security properties
- Test edge cases and failure scenarios
- Review economic incentives
- Suggest protocol improvements
10.3 For Users
- Learn about protocol design
- Understand trade-offs
- Review the SDK documentation
- Test on testnet before mainnet deployment
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
| Parameter | Recommended Value | Rationale |
|---|---|---|
| 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
| Transaction | Recommended Fee Rate | Notes |
|---|---|---|
| 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
- CPFP Support: Claim transaction can be fee-bumped using Child-Pays-For-Parent
- Funding UTXO: Keep a separate UTXO (10,000+ sats) for fee bumping
- Monitor Mempool: Use mempool.space to track fee conditions before initiating swaps
- Avoid Congestion: Wait for mempool to clear below 50 sat/vB for non-urgent swaps
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
11. Additional Resources
11.1 Testnet Faucets
- Bitcoin Testnet: https://testnet-faucet.mempool.co
- Lightning Testnet: https://faucet.lightning.community
11.2 Documentation
- Bitcoin Core: https://bitcoin.org/en/bitcoin-core/
- LND: https://docs.lightning.engineering
- Ord: https://docs.ordinals.com
- Lightning BOLTs: https://github.com/lightning/bolts
11.3 Community
- GitHub: github.com/ProtocolSparkle/Sparkles-Protocol
- X / Twitter: @SparkleProtocol
- Issues: Report bugs or suggest features