Getting Started
This documentation is designed for COMIT-app developers
Since this documentation is designed for developers building applications on top of COMIT we focus on getting you started for developing on top of COMIT. If you are not a developer or want to learn more about COMIT protocol theory please have a look at the COMIT Protocol section. If you are interested in concepts like e.g. atomic-swaps please have a look at the Core Concepts.
This page of the documentation uses create-comit-app for running a demo that performs an atomic swap locally on your machine. The create-comit-app project is the recommended way to get starting with building applications on top of the COMIT protocol.
On this page we'll run you through:
- How to use
create-comit-app
, - What does
create-comit-app
do and how can it be useful to you, a COMIT App dev, - How to run one the provided example, i.e., run an atomic swap with local blockchain nodes.
While mainly written in Rust, it is actually shipped on npmjs.com as two packages:
While you can build your app in JavaScript, examples and the SDK are written in TypeScript, allowing you to also build in TypeScript.
To use either packages, you need to have yarn
or npm
installed.
In this tutorial we will use yarn
but it can be replaced by npm
in any command below.
TL;DR - Quick Start
Once it says the Environment is ready
, open a new terminal (keep the current terminal running):
Congratulations, you did a Bitcoin to Ether atomic swap!
Long version
create-comit-app
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:
Run a demo
The template COMIT App comes with a number of examples and demo projects that allows you to get inspired and run atomic swap between the various supported assets.
Let's run one of those demos to see how an atomic swap execution looks like:
If start-env
from the previous section is still running, leave it. If not, you need to start it:
Then, from a new terminal:
Congratulations, you did a Bitcoin to Ether atomic swap!