Atomic swap

Atomic swap is a method of rapid exchange between two cryptocurrencies operating on different blockchains, without an intermediary representing some exchange. This process (known as atomic cross-chain trading) is based on smart contracts and allows users to trade coins directly from their wallet to store cryptocurrency. As a result, control over the transaction is carried out exclusively by the parties involved in it.

Atomic swaps can be carried out both on—chain, that is, directly between blockchains of different cryptocurrencies, and off-chain — outside the blockchain.

The first such exchange was made on September 19, 2017 between the cryptocurrencies Decred and Litecoin.

How does atomic swap work?

Mary has 100 ETH, and she wants to exchange them for an equivalent amount of DEL. The traditional mechanism assumes that Mary should go to the exchange, replenish her account and issues an order to sell her ETH coins. In the case of atomic swap, Mary can directly exchange her ETH for DEL, the right amount of which John has.

First, Mary makes a deposit in ETH to the address of the contract, it acts as a guarantor. When the latter is created, Mary generates a key to access it. She then shares the cryptographic hash of this key with John. Please note that John cannot access Mary’s ETH yet because he only has the hash of the key (the keyhole), and not the key itself.

John then uses the hash provided by Mary to create another secure contract address where his DEL will be stored. To get DEL from John’s «safe», Mary has to use the same key, thus providing her currency to John (due to a special function called hash lock). This means that as soon as Mary demands ETH, John, in turn, will request DEL, and therefore the currency exchange will be completed.

«Atomic swap» structures the transaction in such a way that the parties depend on each other to ensure the successful completion of the exchange. Transactions are created so that if for some reason the transaction is terminated, all funds are returned to their owners after a certain period of time set by each party.

How does it work technically?

When performing atomic swaps, hash timer contract (HTLC) is used. As the name implies, HTLC is a temporary smart contract that includes the generation of a cryptographic hash function that can be verified by the exchange participants. In other words, HTLC requires the recipient of the payment to confirm receipt of funds by generating a cryptographic confirmation of the payment before the deadline. Otherwise, the transaction is invalidated and the funds are returned to the sender.

Issues of atomic swaps

For the successful implementation of atomic swaps in their original form, the user needs to download the blockchains of both currencies. For an average user, this process is extremely inconvenient, but a solution to this problem has already been found in whole or in part.

The Decimal team is actively working on the practical implementation of the concept of atomic swaps and has already offered its users a cross-chain exchange from the DecimalChain blockchain to the Ethereum blockchain for convenient access to the market of decentralized finance built on ERC-20 tokens. To do this, the user only needs to fill out a simple form on his personal console.

Atomic swaps have great potential to improve the cryptocurrency ecosystem, but this has to be tested on a larger scale.

Conclusion

Atomic swaps are still not fully developed for mass use, but this technology leads to significant changes in terms of the interoperability of blockchains and the possibility of cross-chain trading. Thus, this method has great potential for the growth of the cryptocurrency industry, opens up new opportunities for decentralization and peer-to-peer money transfers. Most likely, in the near future, the popularity of atomic swaps will only increase.