What are atomic swaps and how they are used

Atomic swaps are a mechanism to enable true P2P trading of cryptoassets directly on the blockchain. How do atomic swaps work and what is the future of this technology? Atomic swaps are automatic contracts for exchanging crypto assets between blockchains.. The mechanism of smart contracts completely eliminates the need for centralized third-party organizations (exchanges or exchangers) when making transactions and frees the counterparty from the risk. This is one of the few truly decentralized methods of conducting transactions for the exchange of crypto assets. How Atomic Swaps Work “Atomic” (indivisible) is a term for processes that either run entirely or not run at all. In other words, an atomic swap has features that ensure that both parties to a trade meet all pre-set conditions to complete the swap.. Compliance with conditions is guaranteed by smart contracts. In case of refusal of one of the parties or technical problems, the entire operation is completely canceled. Atomic swaps use hash-locked time-based smart contracts (HTLC). These contracts use a mechanism for creating and comparing data fingerprints – a hash function. In addition, the contract sets a time limit – transactions are canceled if at least one of the parties has not fulfilled the terms of the transaction within a predetermined period. For example, two parties may agree to set a two-hour time limit for an atomic swap. In this scenario, the contract will return the deposited coins to their original owners when two hours have passed and not all terms of the transaction have been met.. The HTLC smart contract requires two cryptographic keys: Hashlock key. This key guarantees that the transaction will only be completed when both parties provide cryptographic evidence that they have fulfilled the terms of the transaction. Timelock key. This is a security mechanism that helps the parties to a transaction set a deadline for committing an atomic swap.. The mechanism guarantees that the deposited coins will be returned to the participants of the transaction if the swap is not completed for one reason or another before the deadline. How Atomic Swaps Are Executed Assume that User A and User B have agreed to perform an atomic swap for BTC and ETH. User B wants to exchange his 1 BTC for User A's 15 ETH. First, User B needs to create a contract address to which he will send 1 BTC. After he has made a transaction, the contract automatically generates a special key, which only User B has access to.. This key unlocks the money that the user sent to the smart contract. The contract uses this key to create a hashed representation or encrypted form of the key. User B then sends the hash of the key to User A. Thus, User A only has access to the hashed form of the passcode used to lock User B's 1 BTC.. This hash confirms that User B has blocked the money in the contract, but User A cannot yet access or withdraw it from the contract. After receiving the hashed key, User A uses it to create his own contract address, to which he deposits his 15 ETH. After both parties have locked their money in the smart contract, User B can claim 15 ETH since he has access to a password that reveals the key used by User A to lock the coins in the smart contract. In the process of unlocking the contract address of User A, User B discloses his password to the second participant in the transaction. User A uses it to receive 1 BTC and complete the transaction. In essence, the whole process of an atomic swap comes down to the ability of both parties to provide cryptographic evidence of their actions. User B had to first encrypt the key and then send it to User A. Since he had the original key, he can claim the crypto assets that User A has locked in the smart contract with the encrypted key. However, as one of the conditions for unlocking crypto assets, User B must provide User A with the original key. User A can then access the key and use it to receive 1 BTC. Why Atomic Swaps Are Important An atomic swap is an important interoperability mechanism for blockchains as it removes the need for intermediaries such as cryptocurrency exchanges when trading cryptoassets. It allows traders to transact cross-chain without relying on the infrastructures of centralized trading platforms. Since intermediaries do not participate in atomic swaps, transactions are faster, more accessible, and eliminate the security incidents associated with exchanges based on custodial transactions. Users retain control over their crypto assets as all transactions are carried out from their personal wallets. In addition, cross-chain trading via atomic swaps contributes to the creation of an interoperable cryptocurrency ecosystem.. Atomic swaps make it easier to transact across multiple blockchains. In addition, atomic swaps eliminate the counterparty risk – the transaction is either completed in full or not completed at all. The development of atomic swaps The atomic swap mechanism was first described by developer Sergio Lerner in 2012.. The idea was of interest to the community, but some of the swap processes were not fleshed out.. A year later, Tier Nolan developed a more secure atomic swap procedure.. But it wasn’t until four years later, when the Decred team did an atomic swap between Decred and Litecoin, that the mechanism was successfully tested on a real blockchain for the first time.. A few days later, Litecoin founder Charlie Lee tweeted that the process had been successfully replicated to swap LTC and BTC. The original design of an atomic swap required both parties to a transaction to download to their device the full blockchain of the cryptocurrencies they planned to exchange.. A month after Decred and Litecoin conducted the first atomic swaps, the developers of the Komodo project introduced a “light version” of atomic swaps, requiring only the opening of special payment channels.. At the same time, the participants in the transaction do not need to download blockchains of crypto assets or wait for validators to confirm transactions. In 2017, Zcash developers demonstrated a working version of the XCAT tool (cross-chain atomic trades – atomic transactions between blockchains), with which you can swap BTC to ZEC and vice versa. A few months later, the first atomic swap between Bitcoin Cash and Decred took place. In 2019, the Qtum platform performed atomic swaps on the Bitcoin mainnet, and Blockstream launched atomic swaps on the Liquid sidechain.. There were also attempts to create trading platforms with support for atomic swaps.. In 2019, the decentralized exchange Sparkswap was launched for bitcoin with support for Lightning and atomic swaps.. However, a year later, the site closed due to a small number of users and low liquidity. Perhaps the development of the DeFi industry, the general course of the community towards decentralization, as well as the support of atomic swaps by the largest blockchains will give impetus to the development of technology in the coming years. However, as of 2021, atomic swaps are still a convenient and secure but rare form of transaction that eliminates the need for counterparties and allows users to retain control over their crypto assets.