Skip to main content
A fixed-party vault names its parties when you create it, so they are fixed in its address. In an escrow, a buyer funds it, and an oracle’s signature releases the funds to the seller, or a timeout returns them to the buyer. Anyone can submit either spend, because the address pins each outcome’s outputs: the submitter picks the moment, never the destination.

Your first escrow

Install

You need Rust 1.85 or newer and Node.js 22.13 or later. Set type to module in package.json.

Compile the contract

Save Escrow as escrow.ark and compile it:
Before you run the scripts below:
  • Replace the three keys before you fund the escrow. The scripts use well-known test keys.
  • exit is the operator’s unilateralExitDelay, encoded in seconds with timelockToSequence. A raw delay binds as blocks, and the operator rejects a block-based exit path. It also rejects an exit delay below its minimum.
  • The scripts read unilateralExitDelay on each run, and the escrow address depends on it. If the operator changes its delay after you fund, the scripts derive another address and find no output. Pass the delay you funded with instead.
  • partyAScript and partyBScript are ScriptPubKey values. Each binds as two arguments: .program is the 32-byte tweaked public key (tweakedPublicKey) and .version is 1n. Spend outputs use the full pkScript.
  • timeoutAt is 1700000000, already past, so cancel works as soon as an output arrives.

Complete

complete pays the seller when the oracle signs. The first run prints the escrow address. Fund it with 12000 sats, then run the file again. The seller receives 10000 sats, and the buyer receives the rest.
complete.ts

Cancel

cancel returns the output to the buyer. Fund the printed address, then run the file again.
cancel.ts

Exit if the operator is unavailable

If the operator is unavailable, the parties can still claim the output onchain with unilateral. First unroll it: broadcast the virtual transactions that lead to it. After the unrolled output confirms and the exit delay passes, Bitcoin checks the unilateral path: both parties sign, and the path does not check the outputs. This file pays a Bitcoin address and leaves a 1000-sat fee. Set UNROLLED_TXID, UNROLLED_VOUT, and UNROLLED_VALUE to the unrolled output, and BITCOIN_ADDRESS to the destination.
unilateral.ts