> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spark.money/llms.txt
> Use this file to discover all available pages before exploring further.

# createHTLC

> Create a Hash Time-Locked Contract for atomic swaps.

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

## Method Signature

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

## Parameters

<ResponseField name="receiverSparkAddress" type="string" required>
  The Spark address of the receiver
</ResponseField>

<ResponseField name="amountSats" type="number" required>
  The amount in satoshis to lock
</ResponseField>

<ResponseField name="preimage" type="string">
  The preimage (32 bytes hex) for the HTLC hash lock. If not provided, a deterministic preimage is generated using [`getHTLCPreimage()`](/api-reference/wallet/get-htlc-preimage).
</ResponseField>

<ResponseField name="expiryTime" type="Date" required>
  The expiry time for the HTLC (must be in the future)
</ResponseField>

## Returns

<ResponseField name="transfer" type="Transfer" required>
  The HTLC transfer details
</ResponseField>

## Example

```typescript theme={null}
// 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)
});
```
