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
The Spark address of the receiver
The amount in satoshis to lock
The preimage (32 bytes hex) for the HTLC hash lock. If not provided, a deterministic preimage is generated using getHTLCPreimage().
The expiry time for the HTLC (must be in the future)
Returns
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)
});