BTC - ETH Cross Chain Atomic Swap
ETHSanFrancisco hackathon.
The project won the Consensys Sponsorship Prize on theHU Yao-Chieh, Lee Ting Ting, and Kevin Gau.
Created byWe built the CrossChain Swap environments for Bitcoin and Ethereum respectively. We implemented the mvp of the idea as a demo to visualize the BTC/ETH swapping process. Description on project deatils is available on Devpost with the Demo Video on Youtube
End-to-end Test Case
- Open Ethereum private node:
ganache-cli
- Open Bitcoin private node (after downloading bitcoin core):
bitcoind -txindex -regtest -reindex -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332
- Host the html site on port 9000:
serve-https /Users/tingtinglee/hack/WEB-v2-BTC/examples/swap/swap-e2e-local.html -p 9000
- In the browser, GOTO https://localhost:9000/examples/swap/_swap-e2e-local.html
- Fill in Bitcoin params: 100000 (or any)
- Click on Generate Secret
A Initiates SWAP on Bitcoin
- Copy over Secret Hash to Bitcoin Initiate Swap
- Click on Initiate Swap
B Initiates SWAP on Ethereum
- Fill in Secret Hash at Ethereum Initiate Swap
- Click on Initiate Swap
A Claims SWAP on Ethereum
- Fill in Secret from A
- Fill in Initiate Transaction Hash from B's Initiation on Ethereum
B Claims SWAP on Bitcoin
- Fill in Secret from A
- Fill in Initiate Transaction Hash from A's Initiation on Bitcoin
Addresses
- A's BTC address: muWrnsfYwzv24sAuC1t45JssWttHUtA162
- A's ETH address: 0x5a3df33ebab91eb80712493c8ad30855b882c669
- B's BTC address: muT9jzX9Jws7X9xE6JZkXcNrzNAfQRDaj9
- B's ETH address: 0x1cdf3aac5329aa9d1dee420468a72bad24055885
Bitcoin tips
Host Bitcoin private net
bitcoind -txindex -regtest -reindex -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332
Interact with the Bitcoin private net via console
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 <function_name> <function_param>
Generate a Bitcoin address
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 getrawchangeaddress "legacy"
get help
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 help
import private key
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 importprivkey cVuHNLamShn9pJEVQLy76fdzLPZxgfhenVdK7wo1vBweue4x2dHv
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 importprivkey cTYiTKhEujcjM4xqgzRHbpCc9Mbtpvqd8VpsRUB6aXygBgg5JsYp
generate 100 blocks
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 generate 101
fund an address
bitcoin-cli -rpcpassword=local321 -rpcuser=bitcoin -rpcport=18332 sendtoaddress muT9jzX9Jws7X9xE6JZkXcNrzNAfQRDaj9 10
Examine on console
Check bitcoin balance
bitcoin.getBalance(["muT9jzX9Jws7X9xE6JZkXcNrzNAfQRDaj9"]).then(console.log)
Chain Abstraction Layer
⚠️ This project is under heavy development. Expect bugs & breaking changes.
Query different blockchains with a single and simple interface.
Installation
npm install @liquality/chainabstractionlayer
Error: Cannot find module 'babel-runtime/core-js/get-iterator'
Issues to track: LedgerHQ/ledgerjs/issues/211, LedgerHQ/ledgerjs/issues/218
npm install babel-runtime
Usage
import { Client, providers } from '@liquality/chainabstractionlayer'
const { BitcoinRPCProvider } = providers.bitcoin
const bitcoin = new Client()
bitcoin.addProvider(new BitcoinRPCProvider('http://localhost:8080', 'bitcoin', 'local321'))
bitcoin
.generateBlock(1) // returns Promise
.then(console.log) // Array<BlockHash>
Community
Try ChainAbstractionLayer in Browser
Chain | Wallet Provider | |
---|---|---|
Ethereum | Ledger | Source & Demo |
MetaMask | Source & Demo | |
Bitcoin | Ledger | Source & Demo |
Documentation
The documentation is being generated by esdoc. Github Page hosted documentation is available at liquality.github.io/chainabstractionlayer
If you want to build documentation locally;
npm run build:docs