Atomic swap (ACCS) lets two parties trade bitcoins without middlemen.
In development: Supported blockchains are limited. Classic smart contracts aren’t needed for the exchange.
It overcomes the issue of performing connected transactions in unrelated blockchains, where both parties must fulfill their contract acts or the transaction would fail. Implementation possibilities:
Some blockchains support on-chain. Lightning Network and Raiden are developing off-chain payment channels. Even test networks lack ready-made implementations.
The content was written by the blockchain development business AXIOMA GROUP, thus it’s appropriate for readers with a basic understanding.
Hashed Time-Locked Contract is the underlying tool (HTLC). This is a method for cryptographically confirming the legality of time-separated participant activities. This tool combines two ways to stop a transaction’s exit: time (time lock) and a secret number whose hash is published on the blockchain (hash lock). Such a system provides transaction reversibility if one party “disappears,” or doesn’t complete the needed activity. HTLC is utilized in the Lightning network. HTLC support and the same hash function are required for an atomic exchange between two blockchains.
Blockchain shouldn’t enable transaction flexibility to prevent fraud. The transaction ID can’t change randomly since it might confuse the exchange partner. Segwit on the blockchain addresses this possible weakness and is a need for ACCS.
ACCS payments
ACCS and payment channels have similar principles, yet they’re different. A couple may make several transactions by creating a payment channel. To trade across blockchains, create a payment channel in each. Participants then terminate the payment channel, fixing the trade on the blockchain.
Exchanging via the payment channel is quicker than waiting for the partner to act.
First-ever Lightning network Bitcoin-Litecoin trade.
Blockchain-based ACCS
Alice and Bob swap items. Bob gives Alice 1 BTC and 10 LTC. Parties agreed to pay blockchain commissions themselves.
Alice and Bob trade new addresses. Bob gives Alice the LTC blockchain address AA and the BTC address AB.
Alice produces a secret key K and its hash KX. Alice makes a 1 BTC TA contract. TA is added at Wta.
Alice provides Bob the TA information, and he learns the KX hash and validates the contract.
If everything is in order, Bob creates a 10 LTC TB contract. VTB adds TB to the blockchain. Bob explains TB to Alice.
Alice reviews the TB contract. She must enter her LTC address, which she supplied to Bob in the first stage. The contract must cost 10 LTC, matching the original agreement. “Secret hash” must match the hash of Alice’s secret key KX from step 2. The contract must also be valid; the specified Locktime must enable the transaction.
Alice sends 10 LTC from transaction TB to another wallet address. Alice reveals the K to Bob. Bob may now access transaction TA.
Bob transfers 1 BTC from TA to another wallet address. It’s over now.
Bob may use TA monies if he learns key K within (Wta, Wta + 48 hours). Alice may use unused cash after BTA+48 hours.
Alice may spend TB money with key K within (Wtb, Ttb + 24 hours). Bob may return unused payments after Wtb+24 hours.
Alice had 10 LTC less the LTC transaction cost and spent 1 BTC plus its fee. Bob spent 10 LTC and 1 BTC after transaction fees.
Due to contract delays, each party has time to obtain its due. Alice can obtain her BTC after 48 hours if Bob doesn’t make a TB contract. Bob will get LTC in 24 hours if Alice doesn’t get TB money. Alice will reclaim Bob’s BTC after 48 hours.
This two-contract transaction is atomic. Each gets his due, or both keep their own, less commission.
Also Read: What Are The Benefits You Can Reap Using Mobile Bitcoin Wallets