Skip to main content
Creates a Hash Time-Locked Contract (HTLC) for atomic swaps and conditional payments.

Method Signature

async createHTLC({
  receiverSparkAddress,
  amountSats,
  preimage,
  expiryTime,
}: {
  receiverSparkAddress: string;
  amountSats: number;
  preimage?: string;  // Optional - auto-generated if not provided
  expiryTime: Date;
}): Promise<Transfer>

Parameters

receiverSparkAddress
string
required
The Spark address of the receiver
amountSats
number
required
The amount in satoshis to lock
preimage
string
The preimage (32 bytes hex) for the HTLC hash lock. If not provided, a deterministic preimage is generated using getHTLCPreimage().
expiryTime
Date
required
The expiry time for the HTLC (must be in the future)

Returns

transfer
Transfer
required
The HTLC transfer details

Example

// With auto-generated preimage (recommended)
const htlc = await wallet.createHTLC({
  receiverSparkAddress: "spark1...",
  amountSats: 10000,
  expiryTime: new Date(Date.now() + 3600000) // 1 hour from now
});
console.log("HTLC created:", htlc.id);

// With custom preimage
const htlcWithPreimage = await wallet.createHTLC({
  receiverSparkAddress: "spark1...",
  amountSats: 10000,
  preimage: "abc123def456...", // 32 bytes hex
  expiryTime: new Date(Date.now() + 3600000)
});