The 4-Transaction Staking Flow
Every BTC Locker position follows the same four-transaction sequence. Before the flow begins, two P2WSH scripts are constructed — a Timelock script and an Escrow script — both using the same deadline so you can exit in a single operation.1
Deposit
You broadcast a Bitcoin transaction that funds both scripts simultaneously:
- The Timelock (Return) script receives a portion of your principal. Only you can spend it, and only after the deadline.
- The Escrow script receives the rest. The provider can claim this before the deadline; you can reclaim it after.
OP_RETURN output carrying a 60-byte SNDL metadata payload. This payload embeds the transaction type (0x01), a UUID identifying your deposit, and the provider’s x-only public key — allowing the Sundial protocol to track and verify the position on-chain.2
Claim
Before the deadline, the yield provider sweeps the Escrow UTXO to their own address. They use the
OP_ELSE branch of the Escrow script, which requires only their private key and has no time constraint on the upper bound.If the provider fails to claim before the deadline, the Escrow UTXO remains unspent and you can reclaim it yourself during the Withdraw step.3
Distribute
After claiming, the provider sends funds back to your Timelock address — your principal plus the agreed yield. This is a standard Bitcoin transaction from the provider’s wallet to your Return script address.There is no on-chain link between the Claim and Distribute transactions. The connection between what the provider claimed and what they return is enforced by the off-chain signed agreement you establish with the provider before depositing.
4
Withdraw
Once the deadline passes, you broadcast a single Bitcoin transaction that spends both UTXOs:
- The Timelock script via
OP_CHECKLOCKTIMEVERIFY— the script unlocks as soon asnLockTime ≥ locktime. - The Escrow script via the
OP_IFbranch — also gated byOP_CHECKLOCKTIMEVERIFY, so it only becomes spendable after the deadline.
Script Mechanics
Understanding the two scripts helps you see exactly what Bitcoin enforces and what it does not.Timelock (Return) Script
Timelock (Return) Script
OP_CHECKLOCKTIMEVERIFY enforces a lower-bound time lock: the spending transaction’s nLockTime must be greater than or equal to locktime before the script will execute. Only the holder of user_pubkey can spend this output — no other party holds a key for it.Escrow Script
Escrow Script
OP_IF branch is your reclaim path: available only after the deadline, requiring your signature. The OP_ELSE branch is the provider’s claim path: available at any time, requiring only the provider’s signature with no upper-bound time constraint. Both scripts share the same deadline value so you can spend both in the same transaction after the deadline.Trust Model
BTC Locker v0 is a custodial yield protocol. Here is exactly what Bitcoin enforces and what it does not:- What Bitcoin Enforces
- What Bitcoin Does Not Enforce
Bitcoin’s
OP_CHECKLOCKTIMEVERIFY can enforce a lower bound on time (“not before X”) but has no opcode for an upper bound (“not after X”). This is why the provider’s OP_ELSE claim path has no time ceiling — it is a fundamental Bitcoin constraint, not a protocol design choice.Race Condition Warning
OP_RETURN Metadata
Every protocol transaction embeds a 60-byteSNDL metadata payload in an OP_RETURN output. This allows Sundial to track staking positions on-chain without any trusted indexer.
You can verify any Sundial transaction on Bitcoin testnet using the live transaction examples: