visit
If you want to buy or sell cryptocurrency, currently you have only one good option: to use a centralized exchange.
For that reason we made , compatible with exchanges like Binance. But certainly there are better ways to exchange cryptocurrencies. Centralized exchanges have some big problems. For starters, just in the past couple months we’ve lived through two exchange hacks where hackers made off with and . And it’s not just hacks either. Exchanges charge high withdrawal fees and trade fees, costing crypto traders a lot of money. The great irony is that cryptocurrency gave us a way to transact money peer-to-peer, but we still have to go through a third party to exchange them. Thinkers in crypto have been working hard on solving this. Among their ingenious solutions, one of the most promising is called an Atomic Swap.Oh Rick After some deliberation, he figures it’d be much better to sell to another person directly, instead of through a shop or a broker. He clicks around in an online forum for a while and comes into contact with a woman named Alice, who wants to buy his coins for $27,000 in cash. Score! But after some back and forth something becomes obvious: neither of them trusts the other enough to mail over their share first. So what do they do? They use a recent invention in this fictional world called a Super Safe Swap. These utilize something called a Super Safe, a safe that looks like a microwave oven. Each has a door, a window and a button that opens the door, and two of them are connected together to do a Super Safe Swap.
Warning: Super Safes do not have the ability to heat up food.
They connect them together. From this point on their doors will only open if the button on both safes is pressed at the same time.
Alice and Bob put their items (cash and coins respectively) in their safes and close it. They share their location, then find their way to the other’s safe. Upon arrival, they peek through the safe window and check whether it contains the right items. If they’re happy with the contents, they press the button. If they both press the button indicating they’re okay with the swap, both safe doors pop open. Alice can take Bob’s gold coins, and Bob can take Alice’s cash, and they both walk away happy. But if either Alice or Bob doesn’t want to go through with the swap anymore, they don’t press the button. Neither Safe pops open, and neither person gets the other’s items. Nobody can steal because the swap either happens completely or not at all. With the Super Safe they’re able to make a trade without a middleman and without having to trust each other.Imagine Bob has 0.05 Bitcoin that he wants to swap with Alice for 1 Ether. Let’s how we would use an Atomic Swap to do this.
Thinking back to the Super Safe Swap, we need a container to put our money in and lock it. For this, we use a special type of called a hashlock.
Calculating the hash from the preimage in step 2 is easy, but calculating the preimage given the hash is (nearly) impossible. This means that Bob can’t unlock the coins unless Alice gives him the preimage.
This is analogous to locking cash in the Super Safe.Initial transaction
Bob checks to see whether Alice has sent a hashlock contract for 1 Ether. He can verify this by looking at the public blockchain. Thereafter Bob sends Alice a hashlock contract for 0.05 Bitcoin that is locked by the same hash as Alice used. This locks the two transactions together, analogous to the linked safes in a Super Safe Swap.
Reciprocal transaction
When Alice wants to unlock the Bitcoin that Bob sent her, she’ll need to use the preimage (secret passcode) to unlock it.
But when she does that, the preimage goes onto the blockchain and becomes public information. Bob can then use it to unlock Alice’s 1 Ether, because the same hash was used to lock both contracts.
So you can see that just like in the Super Safe Swap, this swap happens atomically. Either the trade executes successfully for both parties, or it doesn’t go through at all. But there’s a big problem we didn’t consider: what if Alice never shows the preimage to unlock Bob’s Bitcoins? Then both contracts would remain forever locked.So let’s add one: If after 24 hours Alice hasn’t shown the preimage, then refund both contracts. This is called the timelock.
Hashlocked transactions with timelock Now, if Alice doesn’t show the preimage in 24 hours, Bob can get back his 0.05 Bitcoin, and Alice her 1 Ether. Sounds good, right? But there’s still a way that Alice can cause jeopardy.
The final product And there you have it: A fully functional Atomic Swap!