Skip to main content

Install the SDK

If you haven’t already, install the SDK and set up your environment
A simplified Hash Time Locked Contract with two spending paths using Bitcoin Tapscript opcodes.

Build the Tapscript

Collaborative path (offchain, instant)

The receiver reveals the preimage and signs with the server:

Unilateral path (onchain, timelocked)

After the exit delay, the receiver can claim without server cooperation:

Assemble the VtxoScript

Spending the VHTLC

Collaborative claim (receiver + server)

The witness for the collaborative path includes: <preimage> <receiverSig> <serverSig>. The server validates the preimage hash before co-signing.

Script breakdown

For production code, consider using the TypeScript SDK’s VHTLC.Script class which handles validation and provides a cleaner API.

Next steps

Lightning swaps

Use VHTLCs for Lightning Swaps

Deep dive

Learn about VTXOs and timelocks