Blog

How to: cross chain swaps between Ethereum and Bitcoin

With the number of exchanges going down being abundantly clear, many have asked the question: how can we fix this broken system?

While we know that there is a demand for a safer exchange, there are other ways we can improve this broken system.

Why do I have to provide ID to trade? Why should I have arbitrary account limits? Why do I even need to create an account?

Well I am here to tell you that it is possible to do all these things today by cross chain swaps of Bitcoin (and other SPV currencies like Litecoin) for Ethereum (and derivatives of Ethereum) and in this article I will show YOU how it can be done!

btcrelay

btcrelay is a protocol invented by Joseph Chow that allows verification of the Bitcoin blockchain in Ethereum via SPV proofs.

If you are scratching your head wondering what an SPV is, it is basically a light node for Bitcoin and similar cryptocurrencies.

In essence, btcrelay allows you to verify Bitcoin transactions inside an ethereum smart contract.

The implications of this technology are huge as they allow anyone to create services that facilitate swaps between different cryptocurrencies as well as other services that rely on information across chains.

Some of these services we cannot even imagine yet…

How to swap your Bitcoin for some Ethereum

Now that we are familiar with what btcrelay is, we can now begin to think about implementing it in a smart contract.

In a nutshell, this system works by creating a fresh bitcoin address designed to recieve bitcoins in exchange for ethereum, implementing a contract that can read the Bitcoin blockchain using btcrelay, setting a daily rate between Ether and Bitcoin and providing some liquidity inside the smart contract to pull of the trade.

Bitcoin and Ethereum both use the same key generating algorithm, meaning a buyer can send some bitcoin to your address and receive ether on the same key that they used to send the bitcoin.

The smart contract is able to check that the transaction occurred and was sent to your address, calculate the daily rate set by you and send back the corresponding amount of ether directly to the buyer who sent the bitcoin.

It is not possible for the buyer to cheat by claiming someone else’s bitcoin transaction, nor can the seller refuse to give the ether as it is possible to redeem the transaction in the smart contract and it is also possible to observe the daily rate and liquidity of the smart contract.

The buyer can also verify the SPV used in btcrelay to ensure that it is correctly representing the Bitcoin blockchain.

You can see a draft implementation of this by clicking here.

In essence, this smart contract allows a decentralised swap of bitcoin for ether with complete certainty and without ID verification, an account, fear of the exchange going down or arbitrary limits.

Conclusion

I hope that this article gave you some insight into how cross chain swaps can occur and how the technology is already here today to make for a better trading experience.

What are your thoughts on the future of cryptocurrency exchanges? Leave your comments below