Skip to content

Permissionless-Software-Foundation/bch-dex

Repository files navigation

bch-dex

js-standard-style semantic-release Join the chat at https://gitter.im/Permissionless-Software-Foundation/psf-dex-dev

bch-dex is a decentralized exchange for permissionless trading of SLP tokens and NFTs. Trading fees are incredibly small, compared to other DEX platforms. The software is based entirely on open protocols and open source software. It's not a '.com' website that you visit, but software you run on your own computer, in the confort of your own home. So long as you have an internet connection and the technical knowledge to run this software, no one can stop you from trading tokens. bch-dex software is maintained by the Permissionless Software Foundation.

This is a prototype web service that monitors the P2WDB for trading signals, to trade BCH and SLP tokens. It's inspired by the SWaP Protocol.

This repository contains the back end code. The user interface is contained in the bch-dex-ui repository.

Warning: This repository is under active development. Things will be constantly changing and breaking.

Media

Participate

This is an open source project, and we encourage other JavaScript developers to participate in its creation and maintenance. We have two chat rooms for the community:

Installation

Running the DEX requires composition of these different software packages:

  • bch-dex - This repository is the back end software that tracks trade data on the network, generates Offers and Counter Offers, and finalizes trades by accepting Counter Offers.
  • bch-dex-ui is a Gatsby web app and user interface (UI) for bch-dex.
  • P2WDB is a censorship-resistant database used to communicate trade data between peers running bch-dex.
  • IPFS is a censorship-resistant network for communicating data over the internet.
  • MongoDB is a database used by both P2WDB and bch-dex to store and manage local data.

The above software is orchestrated using Docker and Docker Compose. The target operating system is Ubuntu 20+, and the target hardware is amd64 (normal desktop PCs) and the arm64 (Raspberry Pi 4). Trying to operate this software on other operating systems or hardware is possible, but not supported.

The Raspberry Pi 4 is the primary hardware target, because this software functions best when it is always running. The Pi 4 makes a great appliance for monitoring trade signals and finalizing trades.

Instructions for setting up Node.js, Docker, and Docker Compose can be found in this Gist. Walk-through videos can also be found on the PSF Videos page.

Here are the steps involved in setting up bch-dex:

  1. Follow the direction in this Gist to install Node.js, Docker, and Docker Compose.
  2. Clone the repository with git clone https://github.com/Permissionless-Software-Foundation/bch-dex and enter it with cd bch-dex.
  3. Install dependencies by running npm install
  4. Create a wallet:
  • cd production/scripts
  • node create-wallet.js
  1. Change directory to the production/docker or production/rpi-docker folder depending on your hardware target.
  2. Pull the Docker images down from Docker Hub: docker-compose pull
  3. Start the Docker containers with docker-compose up -d
  4. Wait for the P2WDB to sync and populate bch-dex with trade data. You can monitor it with docker logs --tail 20 -f p2wdb.
  5. Open a web browser and navigate the http://localhost:4500. You'll be able to see new Offers as they come in and are detected by bch-dex.
  6. To take the other side of the trade, click the Take button in the UI.
  7. You can add the 12-word mnemonic from the wallet.json file to the the web wallet, which will mirror your wallet in the UI, and allow you to perform basic wallet functions (send and receive BCH and tokens).

Blockchain Infrastructure

The P2WDB and bch-dex containers requires a 'Global Back End' (as described in CashStack.info) in order to connect to the blockchain. By default, the Docker containers connect to free-bch.fullstack.cash. Several community-provided Global Back End servers are provided and can be viewed here. The back end can be changed by setting the CONSUMER_URL environment variable in the docker-compose.yml file.

Applying Software Updates

As this is an active project, software updates will happen frequently. To apply a software update, perform these steps.

  1. Enter the docker or rpi-docker folder, depending on your hardware target.
  2. Bring down the Docker containers with docker-compose down.
  3. Pull in the software updates with git pull
  4. Update dependencies with npm install
  5. Pull new Docker images with docker-compose pull
  6. Clean up disk space by deleting old Docker images with ./cleanup-images.sh
  7. Start the Docker containers with docker-compose up -d

Sometimes it may be necessary to delete the databases before applying a software update. This can be done by stopping the Docker containers and deleting the production/data directory. When the Docker containers are restarted, they will recreate that directory. The P2WDB will re-sync and bch-dex will be populated with fresh trade data.

License

MIT