Atomic Swaps

Intermediate
March 29, 2023
Read time:
5m

An Atomic Swap is a method of exchanging cryptocurrencies between two different blockchains without the need for an intermediary. Since it’s based on the blockchain, atomic swaps allow for secure transactions and operate on smart contracts.

To perform an exchange like this, both parties must generate a unique code. Once each transmits their code, the transaction is executed and assets are sent from one wallet to another.

Atomic Swaps in practice

In practice, Atomic Swaps use HTCL (hash timelock) technology that locks the transaction and requires the agreement of both parties to complete the exchange.


The contract generated with HTCL includes security features: HashLock and TimeLock. HashLock allows you to lock the contract with a unique key. Deposited assets can only be unlocked by using this key.


TimeLock guarantees the execution of a transaction within a specified time frame. If the transaction is not executed, this mechanism ensures the return of funds to the original address.


The Atomic Swap process begins with creating a smart contract that defines the terms of the exchange, such as the exchange rate or expiration time. Next, one locks up the appropriate amount of cryptocurrency with a smart contract to ensure the security of these funds. The smart contract then verifies the transaction, and if the conditions for its execution are met, the transaction is executed and completed.

Example of Atomic Swap

Below is an example of an atomic swap between cryptocurrency A and B:

Let's say Sophia has 100 units of cryptocurrency "A" and wants to trade them for cryptocurrency "B" with Nick, who has 50 units of asset "B". Sophia and Nick agree to exchange their tokens for a fixed amount.

The smart contract notices that they agreed to exchange their tokens for a given amount of the other and
executes the trade for them. This automation is made possible by HTCL.

The transaction between Sophia and Nick is
recorded on the blockchain and validated by network nodes. Then, a new block is opened for another transaction. Sophia receives 50 units of "B" tokens, and Nick receives 100 units of "A".

Transactions
cannot be reversed, so if either party wants to retrieve their tokens, Nick and Sophia must agree to another transaction to exchange the assets again.


Since transactions cannot be reversed, if any party wants to have their tokens back, they would have to agree to another transaction to exchange the assets again.

Summary

In conclusion, the atomic swap process is a safe and direct way to exchange assets in the cryptocurrency market. By using smart contacts, transactions are secured and do not require the involvement of an intermediary.

Complete quiz
Atomic Swaps
Share this article
Explore other articles
Beginner

Interview with prof. Aleksandra Przegalińska

In a 40-minute interview, prof. Przegalińska answered questions about predictions regarding the fate of web3, NFT, and Metaverse, her personal and academic experiences in Second Life and her opinion about Mark Zuckerberg's Meta project.
Advanced

Exponential Moving Average (EMA) and Simple Moving Average (SMA)

Exponential Moving Average and Simple Moving Average are two technical indicators used in financial analysis. While SMA calculates the average price over a specific time by taking the arithmetic mean of the closing prices, EMA places more weight on recent prices.
Beginner

How to safely purchase cryptocurrencies?

Crypto security should be your top priority if you are a crypto trader. Lack of transparency and scarce information on technology and security measures are red flags if you are looking for a reliable crypto exchange.