What are atomic swaps and who uses them
Atomic swaps are mechanisms that enable a secure P2P exchange of cryptocurrencies. They are based on bilateral smart contracts, removing third-party involvement in the transaction.
Atomic (i.e. "indivisible") swap is one of the few DEX techniques for exchanging cryptocurrencies on different blockchains. It is an inter-network trade based on the philosophy of direct interaction between network users. Token holders can exchange their coins, without using the services of crypto exchanges.
How do atomic swaps work?
Smart contracts for swapping are created in the L2 payment channel of the Lightning Network, with a commission of 1 satoshi per transaction.
The whole swap procedure can be divided into the following steps:
1. Two people agree to swap their coins at a rate beneficial to both parties. Imagine that user John offers his BTC in exchange for Michael's BCH.
2. John deposits bitcoin to the contract address, which acts as a temporary vault.
3. When coins are deposited into this vault, the smart contract automatically generates a Hashlock Key to access the BTC.
4. John sends the private key to Michael, thereby confirming the fulfillment of his side of the deal.
5. Michael uses the given key to create his contract and sends BCH.
6. Once the transfer is made, Michael gets his Hashlock Key and sends it to John.
7. Bitcoin Cash and Bitcoin are locked in "vaults", and both parties confirm that they have fulfilled their part of the commitments.
8. John and Michael swap the original (public) keys to the temporary vaults and get access to the money.
Atomic Swap Scheme. Source: Github
The parties may agree in advance on the Timelock Key. It can be used when the parties are not sure of the quick fulfillment of the contract. An activated Timelock Key will monitor the action timing. If one of the parties does not create a cryptographic proof of payment within the agreed period, the deposited funds will be returned to the owner.
The specific feature of an atomic swap is that the contract is executed only after the swap is fully completed. If any of the parties fail to send funds or send them in an amount that differs from the declared amount, all the coins will be returned to the owners. This reduces the risk of fraud.
Who can benefit from an atomic swap?
Atomic swaps are used by those who want no third party to participate in the transaction.
These include:
1. Traders who, for whatever reason, do not trust the centralized exchanges.
2. Token holders unwilling to pass KYC procedures on controlled platforms. However, the cloud providers ensure only relative anonymity.
3. Altcoin owners who do not want to (or cannot) use stablecoins or fiat as an intermediate coin for conversion.
All transactions between blockchains are made using personal wallets with no intermediaries or supervisors. There is no need to trust each other because all risks are eliminated during the execution of the contract.
Swap transactions are faster than exchange transactions while fees are kept low.
The major disadvantages of atomic swaps include:
1. Only cryptocurrencies with the same encryption algorithm can be swapped. For example, you can swap Zcash for Comodo, because they have the same Equihash algorithm. But you can't swap Litecoin (Scrypt) for Monero (CryptoNight). Though developers are actively testing solutions to expand possible swapping pairs.
2. This kind of swap requires peers to run full blockchain nodes on their hardware. Yet this problem can be solved by using cloud services for running nodes.
Atomic swaps can be performed on DEX platforms (Uniswap, Atomic DEX, Sushi Swap), using cloud services (e.g. Atomic Papas), or through a Ledger hardware wallet.