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