Skip to main content
You’re viewing an old version of the Arkade contracts documentation. Go to Your first contract for the current version.
A hash time locked contract (HTLC) pays the receiver if they reveal a secret preimage, and refunds the sender after a deadline. Two HTLCs that share one hash make an atomic swap: when the receiver claims one, the preimage becomes public and unlocks the other. The code uses arkProvider, indexerProvider, serverPubkey, exitTimelock, serverUnrollScript, and hex from Set Up Your Project. The exit refund waits longer than the exit claim, so the receiver always has time to claim first.

Build the HTLC

The condition HASH160 <hash> EQUAL checks that the preimage hashes to hash160(preimage), which is RIPEMD160(SHA256(preimage)). Each helper adds VERIFY and the signature checks after it.
The claim path is:

Claim with the preimage

claimWithPreimageIdentity signs as the receiver and attaches the preimage to each input. The operator rejects the spend if the preimage does not match the hash.
To refund after refundAt, pass refundLeaf to findLeaf and sign with sender. The SDK sets the transaction’s locktime from the path. The SDK’s VHTLC.Script builds a six-path HTLC with the same structure. It adds refund paths that the sender and receiver sign together, so they can cancel before the deadline.