Categories
Tutorials

Atomic Swap: how to use these automatic exchange contracts

What is The Atomic Swap?

Atomic swap is a smart contract that allows you to exchange one crypto token with another token, peer-to-peer. In this contract, the user can convert the digital currencies of two different blockchains to each other. But there is a special feature in this exchange: these transactions are done without using centralized intermediaries such as exchanges.

The first atomic swap was made in 2017 between the two currencies Decred and Litecoin. Also, if you want to convert your token to another token, some exchanges may not support the digital currency you want or you may need to convert several currencies to do so. But atomic swap solves this problem.

How Does Atomic Swap Work?

HTLC

HTLC or Hash Timelock Contracts is a time-bound smart contract between the parties in a transaction. It locks the transaction until it is approved between the parties. So this contract acts as a safe net and includes a cryptographic hash function that is validated between the two traders. Atomic swap is one of the few decentralized trading techniques without the need for a third party.

HTCL Contract Benefits

HashLock

This locks the contract with a private key, in which case only the depositor can access the contract. So the deposit of the deposited currency can be unlocked only with the special key of the same contract and it is finally confirmed when both parties submit cryptographic proofs.

TimeLock

This feature determines that the transaction takes place within a specified time frame. If not, the currency will be returned to the parties’ accounts. It then secures the transaction using time constraints. For example, two people can set a time limit of 1 hour for an atomic swap. If the terms of the transaction are not completed in this contract, the currency will be returned to the account of the parties.

Example of an Atomic Swap

Let’s suppose that someone wants to pay 0.5 BTC to buy 7ETH. This person sends his Bitcoin to the specified address. After sending it, the contract automatically gives that person a special key with which he can access the currency he sent through the smart contract.

This person now sends the created hash to the other party to the contract who can see the transaction but cannot access it without a special key. So the second person uses the received hashed key to create his own contract addres. They make 7ETH deposit into that address. Now the first person can claim their own ETHs. After opening the password to claim, the passcode is revealed to the second person. In this case, the second person can also receive his bitcoin using the original key. Then the atomic swap ends.

Benefits of Atomic Swaps

Increase security

Using The HashLock and TimeLock technologies in HTCL contracts, you can experience more security trading with atomic swaps. The parties can have full control over the transaction. Even if the terms of the transaction are not fulfilled, the currency will return to the wallets of the parties. So this assurance makes it easier for people to use atomic swaps.

Decentralized

With atomic swaps, there is no need for centralized exchanges. One of the main purposes of digital currencies is to trade through decentralized exchanges in atomic swaps. The use of wallet-to-wallet transactions allows the parties to have complete control over the transactions.

Peer-to-Peer Trading

With this contract, people can trade with each other independently and all these trades are done in complete security. You also have access to a limited number of tokens here (like most exchanges). Instead, with atomic swaps, you can trade almost all altcoins.

Disadvantages of Atomic Swaps

Complexity of transactions

One of the most difficult conditions for traders is to create complex conditions for atomic swaps. But these complexities are not only to the detriment of the parties. Also to increase their security and hashed cryptographs.

Privacy

If there is a long time for trading, there is a good opportunity for hackers to obtain the private information of traders. So this can be one of the points to consider in transactions because the main purpose of digital currencies is to remain anonymous in transactions.

Conclusion

Due to its high security as well as decentralized trading in atomic swaps, it can be one of the best platforms for traders to exchange all types of altcoins. Having HashLock and TimeLock in atomic swaps can provide the best conditions for trading between the parties. All of these techniques were the idea of Sergio Demian Lerner in 2012. Eventually, the Decred team was able to do an atomic swap between Decred and Litecoin. And turn the Atomic swap into a popular method for trading crypto tokens.