Atomic swaps work by utilizing smart contracts and hashlock cryptographic techniques to secure digital asset exchanges.
“Atomic” is a term used to describe processes that either conclude successfully or do not initiate at all — there is no other alternative. An atomic swap for crypto trading implies only two possible outcomes: Either the trade is successfully executed, or no action occurs.
In simpler terms, an atomic swap creates a mechanism where both sides of the cryptocurrency trade must satisfy all predetermined conditions before the trade can be finalized. This is achieved through the implementation of smart contracts, which are self-executing programs designed to enforce the conditions necessary for a transaction to be successful.
Atomic swaps utilize hashed time lock contracts (HTLCs), which are a form of smart contract, to enable secure and trustless exchanges of cryptocurrencies. HTCLs, in essence, “lock” a transaction and demand that both parties verify the information before the exchange can proceed.
Atomic swap smart contracts have two essential components:
Hashlock
The hashlock mechanism allows the contract to be locked with a unique cryptographic key that can only be generated by the cryptocurrency depositor. This key, which is a unique data piece, ensures that the swap is only finalized when both parties approve the transaction.
Timelock
The timelock mechanism is like a deadline for the swap. It ensures that the transaction is completed within a certain amount of time, and in the event it does not happen, it returns the depositor’s funds. Timelock essentially helps secure the transaction. Both parties must approve the swap within the specified time limit or else the transaction gets aborted and the crypto is returned to its respective owners.
Source: https://cointelegraph.com/explained/what-is-an-atomic-swap-and-how-does-it-work