Development Setup
This documentation section shows an overview of how to setup a COMIT-app for development. The tools around the COMIT protocol are listed and the interaction between them is shown.
Introduction
The COMIT project consists of several projects on GitHub. The reference implementation of the protocol is shipped as binary and is called Comit Network Daemon (cnd).
A swap is executed between two parties. We call them a maker and a taker. While the former one creates orders and makes them available, the latter one can take these orders and initiate the swap execution.
Each party runs its own cnd. Typically those two instances would run separately on different machines. For the development environment they are typically started on the same machine. The two cnd nodes communicate via the COMIT communication protocols for exchanging swap parameters prior to executing the swap. Cnd offers a REST API for executing the cryptographic protocols.
For your local dev setup you will need the following components:
- Two cnd nodes; one for each party of the trade.
- The respective blockchain nodes for the swap. If you are swapping bitcoin for ether you need a Bitcoin and Ethereum node.
- Wallets, corresponding to the ledgers, to send transactions. If you are swapping bitcoin for ether you need a Bitcoin and Ethereum wallet.
You can use comit-scripts to start up a development environment based on docker containers.
The COMIT-app holds all the components together and offers an interface for swap negotiation and execution to the user. A COMIT-app typically includes some mechanism to find trading partners and manage orders because cnd does not support negotiation protocols yet.
This slide shows an overview of the components and their interaction.
Javascript Developers
In order to make COMIT more accessible for Javascript developers we offer the comit-sdk and create-comit-app. Create-comit-app includes the comit-scripts module which includes scripts that setup your development environment.
create-comit-app
create-comit-app
is a project to help COMIT App developers setup an environment.
The create-comit-app
allows you to create a template COMIT App which includes working examples.
To create your template app in the my-app
directory, just do:
Let's have a look at what we have here:
.
is where you can start writing your app, see write your app tuto./package.json
contains some useful dependencies for your app./examples
contains projects that are made to inspire developers such as yourself to build their app./demos
contains projects which are catered for workshops demonstration. They do not have a conventional structure but have verbose output.
comit-scripts
The comit-scripts
package helps you run a development environment to build a COMIT App.
When creating an application with create-comit-app (yarn create comit-app my-app
) it is part of the setup.
Let's install it from the template folder to play with it.
The example package.json
of create-comit-app template includes the start-env
command of comit-scripts
:
When running start-env
the development environemnt is started:
The second command force-clean-env
can be used if the environment unexpectedly crashed and some containers were not removed.
Usually you will not need this command, as Shutdown will properly clean up the containers.
Creating Docker network (create-comit-app)...β
Creates a docker network to allow several docker containers to communicate with each others. The network is named create-comit-app
.
Starting Ethereum node...β
- Starts a parity node in a docker container,
- Deploys an ERC20 token contract
- Creates two accounts,
- Funds each account with 1000 Ethers and 100 ERC20 tokens.
Starting Bitcoin node...β
- Starts a bitcoind node in a docker container,
- Creates two HD wallet,
- Funds each wallet with 10 Bitcoin,
- Mines a new block every second.
Starting two cnds...β
Starts 2 cnd (COMIT Network Daemon) in docker containers.
Let's take a break and check out what containers are now running:
Indeed we have bitcoind, parity and 2 cnds running.
Writing configuration in env file...β
Writes useful information to ~/.create-comit-app/env
.
Let's have a look at this env
file in more details:
We have here the private keys of the funded accounts on Ethereum and Bitcoin and the endpoint to the various services. This can be used to be imported in my-app so that you can test it with funded accounts.
Two cnds?
You may have noticed that you are getting 2 Bitcoin wallet, 2 Ethereum accounts and 2 cnd instances out of start-env
.
This is simply due to the fact that one cannot do an atomic swap by themselves!
Atomic swap are inherently peer-to-peer.
One can only sell Bitcoin for Ether if someone else buys Bitcoin For Ether.
As you need two parties to do a swap, start-env
gives you an environment for both parties.
Shutdown
To stop the environment, just hit CTRL+C
and wait few seconds:
comit-sdk
caution
This section of the documentation is still under construction. Stay tuned for more content!
The comit JavaScript software development kit (comit-sdk) helps integrating swaps into JavaScript applications. It wraps the communication with cnd to simplify creating and executing swaps. It includes a simple negotiation module that can be used to create and take orders.