STC Educational Panel

Atomic Swaps

March 29, 2023
Read time:

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".

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.


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

What is return on investment (ROI)

ROI is a financial metric used to evaluate the profitability and efficiency of investments, expressed as a percentage. It's an excellent tool for comparing the profitability of investments.

Trading journal

Trading journals, if maintained, may record all your trades, including performance and observations, making it easier to avoid emotional decision-making and test different strategies. Interpreting data and answering critical questions can provide a higher level of trading self-awareness, leading to improved results.

What is MACD and how to use it to determine market trends and reversals?

The Moving Average Convergence/Divergence (MACD) is a trading indicator that measures an asset's momentum through two exponential moving averages (EMAs) of different periods.