Skip to content

lukasosterheider/build-on-defichain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Build on DeFiChain with Docker

This repository describes the setup of a DeFiChain node, an Ocean API and the corresponding DeFi Scan Explorer.

You can use this infrastructure to either use your own node with your DeFiChain Light Wallet, run your own DeFiChain Community Project based on your own node or do other cool stuff with DeFiChain.

This tutorial uses docker as a runtime platform. You could also run all components directly on a server.

Table of Contents

Prerequisites

Before you can start, please ensure you have the following components available:

  • A linux-based server that is exposed to the internet - e.g. you could use netcup
  • A DNS domain if you would like to expose services via a DNS name

Install Docker

Before we can run any DeFiChain component, we need to install docker.

You can therefore use the Docker convenience script which makes the installation quick and easy:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Create a docker network for all DeFiChain components (we call it "ocean"):

docker create network ocean

Afterwards add a new user "defichain" and create a data directory:

sudo useradd -m defichain
sudo mkdir /home/defichain/defid-data
sudo mkdir /home/defichain/whale-data
sudo chown defichain:defichain /home/defichain/defid-data
sudo chown defichain:defichain /home/defichain/whale-data

Check out https://docs.docker.com/engine/install/ubuntu/ for more details.

If you want to use docker compose, you can jump to TL;DR;JustUseCompose

Run a DeFiChain Node

docker run -d --rm  \
  -v /home/defichain/defid-data:/data \
  --network=ocean \
  defi/defichain \
  defid \
  -rpcallowip=172.19.0.0/16 \
  -rpcbind=0.0.0.0 \
  -rpcuser=your-user \
  -rpcpassword=your-password

Note: The rpcallowip range must be the docker network IP range.

defi.conf Configuration File

If you want to change the defi.conf, just locate the file at /home/defichain/data/defi.conf

Backup & Restore

You can also easily do backup by making a copy of the /home/defichain/data folder, e.g. cp /home/defichain/defid-data /home/defichain/defid-data-backup

To restore, just stop the container, run cp /home/defichain/defid-data-backup /home/defichain/defid-data and then run the container again.

Check out https://github.com/DeFiCh/ain/blob/master/doc/setup-nodes-docker.md for more details.

Run a DeFiChain Ocean API

docker run -d \
  -p 127.0.0.1:8081:3000 \
  -v /mnt/storagespace/whale/data:/data \
  --network=ocean \
  --env WHALE_DATABASE_PROVIDER=level \
  --env WHALE_DATABASE_LEVEL_LOCATION=/data \
  --env WHALE_DEFID_URL=http://your-user:[email protected]:8554 \
  --env WHALE_NETWORK=mainnet \
  ghcr.io/jellyfishsdk/whale-api

Different Databases

You can choose between the two database types "memory" and "level" (a leveldb). If you choose the level db, you can specify a location where the data is stored. This enables you to take backups of your database.

Backup & Restore

You can also easily do backup by making a copy of the /home/defichain/data folder, e.g. cp /home/defichain/defid-data /home/defichain/defid-data-backup

To restore, just stop the container, run cp /home/defichain/defid-data-backup /home/defichain/defid-data and then run the container again.

Run a DeFiChain / DeFiScan Explorer

To run a DeFiChain Blockchain Explorer, you have to clone, edit and re-build the DeFiCh/scan repository.

I used this approach to build https://explorer.sternberg-partners.de/. You can find the open source repository for the website here.

The following files need to be edited:

  • next-sitemap.js --> change URL
  • src/components/commons/Breadcrumb.tsx --> change URL
  • next.config.js --> add your Ocean API URL to connect-src
  • public/_headers --> add your Ocean API URL to connect-src
  • src/layouts/contexts/Environment.ts --> add additional environments (optional)
  • src/layouts/contexts/NetworkContext.tsx --> add network information if additional environments have been added (optional)
  • src/layouts/contexts/WhaleContext.tsx --> add & edit Ocean API endpoints

You can use the Dockerfile (provided in 'lukasosterheider/scan') to build the application.

Run the container

docker run -d -p 127.0.0.1:8082:3000 container-repo/container-name:tag

Example for my DeFiChain Blockchain Explorer:

docker run -d -p 127.0.0.1:8082:3000 lukasosterheider/defiscan-sternberg-partners:0.1.5

Expose Services to the Internet

To expose the - currently only on localhost available - services, you can utilize nginx as a reverse proxy solution. While further documentation might follow, for now please find more information on the below mentioned websites:

Further Support

Feel free to contact me on Twitter for further support @osterheider.

Buy me a coffee or pizza by donating to (DeFiChain Address): df1qqd3eze5lxc04g835zv8nugu6slww6c5l4yzfcc

About

Some docs about how to build on DeFiChain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •