A real BTC ↔ BTC-PQS swap, with no custody
Two contracts sharing the same hashlock: one on Bitcoin (P2WSH), one on the EVM chain. Nobody holds the keys in the middle. Each side can either claim or recover its funds, under rules the other side cannot break.
Quick start — pick your side
- Buying tokens with BTC? You generate the secret, you get the hash, you keep the secret.
- Selling tokens for BTC? You receive the hash and lock the tokens against it.
- The contract holds the tokens; the BTC waits in a Bitcoin script with the same hash.
- The same secret unlocks both. Nobody in the middle.
New to this? Read the step-by-step guide first.
Before you send BTC — check the swap
Paste the swap id the seller gave you. Read the amount, the hashlock and the beneficiary here, on-chain, before any BTC moves.
Step 1 — generate the secret (it stays with you)
The 32-byte secret is the key that unlocks both sides. Never send it to anyone: the counterparty receives only its hash. Save it before you continue.
- secret (32 bytes)
- —
- hashlock sha256(secret)
- —
Step 2 — build the swap’s BTC address
The P2WSH address is derived locally from the hashlock, from the seller’s address (who receives the BTC when the secret is revealed) and from your address (who can recover the BTC after the timelock, because you funded it). Then check that the address shown is identical to what the seller sees on their page — if it differs, stop.
Rate — 1 BTC = 1 BTC-PQS, fee taken from the new tokens
The issuer policy is 1:1. The contract cannot see the Bitcoin amount, so what it enforces is the exact number the seller locks: enter the BTC amount and lock the figure shown.
Step 3 — once the seller has locked the tokens
swapCount and a Locked event with your hashlock and beneficiary = your address.
Do not send BTC before that.claim(swapId, secret) right below (or from the
web wallet). You receive the locked amount minus the contract fee
(feeBps, 0–5%, fixed at deploy and shown to the seller). The moment you send
the secret it becomes public — that is why the seller needs a time margin before the Bitcoin timelock.T_evm, the seller
can recover the tokens, and you recover your BTC after T_btc.Claim — take the tokens out of the HTLC
Step 1 — get the hashlock from the buyer
The buyer gives you only the hash, not the secret. You use it to lock the tokens.
Step 2 — lock the tokens in the HTLC contract
Step 3 — collect the BTC with the secret
The secret becomes public when the buyer claims the tokens. With it you recover the BTC from the P2WSH address, before the timelock. You need a wallet that signs custom scripts (Sparrow with a miniscript descriptor, or a dedicated tool) — a regular wallet will not work.
The mechanism in 5 sentences
1. The buyer generates a secret S and computes H = sha256(S).
2. The seller locks the tokens in PqHtlcSwap with H, beneficiary = the buyer,
timelock T_evm.
3. The buyer locks BTC in a P2WSH HTLC with the same H, timelock T_btc > T_evm.
4. The buyer calls claim(swapId, S) and receives the tokens; S becomes public.
5. The seller uses S to collect the BTC before T_btc; if they miss it,
the buyer recovers the BTC after T_btc and the seller recovers the tokens after T_evm.
Why it works without trust
No contract can move the funds any other way: tokens leave the HTLC only to the beneficiary holding the correct secret, or back to the initiator after the timelock. BTC leaves the P2WSH only through the branch with the same hash or the refund branch after CLTV. Each side is protected by its own chain’s consensus, not by promises.
Where it can go wrong
- Too small a margin between
T_evmandT_btc: the seller may run out of time to collect. +24h recommended. - Claim sent through a private relay: the seller does not see the secret in time. Use the public mempool or a watchtower.
- Wrong BTC addresses: the money lands in a script you cannot unlock. Check the address twice, on both screens.
- Chain reorganisation: a BTC deposit can disappear. Wait for confirmations.
- A wallet that cannot handle custom scripts: you cannot claim the BTC. Test with a small amount first.