Your first escrow
Install
You need Rust 1.85 or newer and Node.js 22.13 or later. Settype to module in package.json.
Compile the contract
Save Escrow asescrow.ark and compile it:
- Replace the three keys before you fund the escrow. The scripts use well-known test keys.
exitis the operator’sunilateralExitDelay, encoded in seconds withtimelockToSequence. 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
unilateralExitDelayon 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. partyAScriptandpartyBScriptareScriptPubKeyvalues. Each binds as two arguments:.programis the 32-byte tweaked public key (tweakedPublicKey) and.versionis1n. Spend outputs use the fullpkScript.timeoutAtis1700000000, already past, socancelworks 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 withunilateral. 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