// Sparkle Protocol integrates with spark.money SDK
import { SparkWallet } from '@buildonspark/spark-sdk';
// Initialize Spark wallet for Lightning payments
const { wallet } = await SparkWallet.initialize({
options: { network: "MAINNET" }
});
// Inscribe NFT with Sparkle Protocol metadata
const inscription = {
p: "sparkle",
v: 4,
spark: {
enabled: true,
address: await wallet.getSparkAddress()
}
};
// Pay for NFT using Lightning via spark.money
const payment = await wallet.payInvoice({
encodedInvoice: sellerInvoice,
amountSatsToSend: 100000,
preferSpark: true // Use Spark transfer when available
});
console.log('Payment settled:', payment.status);
npm install @sparkle/sdk
yarn add @sparkle/sdk
<script src="https://unpkg.com/@sparkle/sdk@/dist/sparkle.min.js"></script>
new SparkleSDK(config: SparkleConfig)
Creates a new instance of the Sparkle SDK.
network - 'mainnet' | 'testnet' | 'regtest'lightning - Lightning configuration objectrpcUrl - Bitcoin RPC endpoint (optional)apiKey - API key for premium features (optional)sparkle.deploy(options: DeployOptions): Promise<Collection>
Deploys a new NFT collection with recursive inscription support.
name - Collection namesupply - Total supplytraits - Array of trait layer inscriptionslightning - Enable Lightning tradingcheckpointWindow - Blocks for checkpointing (default: 72)sparkle.mint(options: MintOptions): Promise<NFT>
Mints a new NFT with selected traits.
collection - Collection inscription IDtraits - Array of trait inscription IDsrecipient - Bitcoin addressenableLightning - Enable instant tradingsparkle.transfer(nftId: string, recipient: string): Promise<Transaction>
Transfers an NFT to a new owner.
sparkle.checkpoint(nftId: string, state: State): Promise<Checkpoint>
Creates a mandatory state checkpoint on-chain.
// Open Lightning channel for NFT trading
const channel = await sparkle.lightning.openChannel({
nodeUri: '03abc...@spark.money:9735',
localAmount: 1000000, // satoshis
pushAmount: 0
});
console.log('Channel opened:', channel.channelId);
// List NFT for instant sale via Lightning
const listing = await sparkle.lightning.list({
nft: nftId,
price: 100000, // satoshis
duration: 86400 // 24 hours
});
// Buy NFT instantly with Lightning payment
const purchase = await sparkle.lightning.buy({
listing: listing.id,
invoice: 'lnbc...' // Lightning invoice
});
// Transaction settles in <10ms!
// Create HTLC for atomic swap
const htlc = await sparkle.lightning.createHTLC({
amount: 50000,
paymentHash: sha256(preimage),
timelock: 144 // blocks
});
// Claim HTLC with preimage
await sparkle.lightning.claimHTLC(htlc.id, preimage);
import { SparkleSDK } from '@sparkle/sdk';
import fs from 'fs';
const sparkle = new SparkleSDK({
network: 'mainnet',
lightning: { node: 'spark.money' }
});
async function deployDarkita() {
// First inscribe trait layers
const traits = [];
// Inscribe backgrounds
for (let i = 1; i <= 20; i++) {
const svg = fs.readFileSync(`./layers/backgrounds/bg_${i}.svg`);
const inscription = await sparkle.inscribe({
content: svg,
contentType: 'image/svg+xml',
feeRate: 10
});
traits.push({
type: 'background',
id: inscription.id,
zIndex: 0
});
}
// Deploy collection
const collection = await sparkle.deploy({
name: 'DARKITA',
symbol: 'DARK',
supply: 10000,
traits: traits,
lightning: true,
creator: 'bc1p...',
royalty: 2.5 // 2.5%
});
console.log('Collection deployed:', collection.inscriptionId);
return collection;
}
deployDarkita().catch(console.error);
// Create marketplace with Lightning support
class SparkleMarketplace {
constructor(sdk) {
this.sdk = sdk;
this.listings = new Map();
}
async listNFT(nftId, priceInSats) {
// Create Lightning invoice for payment
const invoice = await this.sdk.lightning.createInvoice({
amount: priceInSats,
description: `NFT Purchase: ${nftId}`
});
// Store listing with HTLC
const listing = {
nft: nftId,
price: priceInSats,
invoice: invoice,
htlc: await this.sdk.lightning.createHTLC({
amount: priceInSats,
paymentHash: invoice.paymentHash
})
};
this.listings.set(nftId, listing);
return listing;
}
async buyNFT(nftId) {
const listing = this.listings.get(nftId);
// Pay Lightning invoice
await this.sdk.lightning.pay(listing.invoice);
// Transfer NFT atomically
await this.sdk.transfer(nftId, buyerAddress);
// Settlement in <10ms!
return { success: true, txid: transfer.txid };
}
}
Sparkle SDK includes comprehensive TypeScript definitions for type-safe development.
import {
SparkleSDK,
Collection,
NFT,
LightningChannel,
SparkleConfig,
DeployOptions,
MintOptions
} from '@sparkle/sdk';
// Type-safe configuration
const config: SparkleConfig = {
network: 'mainnet',
lightning: {
node: 'spark.money',
capacity: 1000000,
autopilot: true
}
};
// Async/await with proper types
async function mintNFT(): Promise {
const sparkle = new SparkleSDK(config);
const options: MintOptions = {
collection: 'ord://...',
traits: ['trait1', 'trait2'],
recipient: 'bc1p...',
enableLightning: true
};
return await sparkle.mint(options);
}
interface NFT {
inscriptionId: string;
tokenId: number;
collection: string;
traits: string[];
owner: string;
lightning: {
enabled: boolean;
channelId?: string;
invoice?: string;
};
metadata: Record;
}
interface Collection {
inscriptionId: string;
name: string;
symbol: string;
supply: number;
minted: number;
traits: Trait[];
checkpoint: {
window: number;
lastBlock: number;
merkleRoot: string;
};
}
Sub-10ms NFT trades through Lightning Network integration
SHA-256 verification and HTLC atomic swaps
Recursive inscriptions minimize on-chain data
Mandatory checkpointing ensures canonical state
Full type definitions for type-safe development
Design phase — not yet implemented