KGI is comprised of four components:
- A postgres database
- A
processing
kaspa node (this is simply a kaspad wrapped in some extra logic) - An
api
REST server - A
web
server
How the components interact:
- The
processing
node connects to the Kaspa network the same way a regular kaspad node does and starts syncing just as a kaspad node would - While it's syncing, it writes metadata about every block to the postgres database
- From the other end, the
web
server listens to http requests on some port - When a user navigates their browser to that port, the
web
server serves the KGI clientside logic, which includes the UI - The clientside logic calls the
api
REST server every so often - The
api
REST server queries the postgres database and returns it to the clientside - The clientside uses the response it received from the
api
REST server to update the UI
For development, it's recommended to run KGI from within Docker
- Make sure you have docker installed by running
docker --version
- Make sure you have docker-compose installed by running
docker-compose --version
- Define the following environment variables:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=database-name
- API_ADDRESS=localhost
- KATNIP_ADDRESS=localhost
- API_PORT=4575
- WEB_PORT=8080
- KASPAD_VERSION=4a560f25a60e876b58d2643ca6eb7e07525e76cc (this can be either a specific kaspda commit hash or a kaspad tag)
- KASPA_LIVE_ADDRESS=localhost
- Run:
./docker-run.sh
- Deploy a postgres database instance in any way you desire. Note the address, port, username, password, and database name, since these will be required later
- Build
processing
- Make sure the go build environment is set up by running
go version
- Within the
processing
directory, editgo.mod
:- Delete the line that starts with
replace github.com/kaspanet/kaspad
- Set your desired kaspad version in the line under
require
that starts withgithub.com/kaspanet/kaspad
- Delete the line that starts with
- Within the
processing
directory, rungo build -o kgi-processing .
. This will produce an executable file namedkgi-processing
- Copy
kgi-processing
anddatabase
directory (also within theprocessing
directory) to wherever you wish to run the node from
- Make sure the go build environment is set up by running
- Build
api
- Make sure the nodejs build environment is set up by running
npm version
- Within the
api
directory, run:npm install
- Copy the entire
api
directory to wherever you wish to run theapi
server from
- Make sure the nodejs build environment is set up by running
- Build
web
- Make sure the nodejs build environment is set up by running
npm version
- Within the
web
directory, run:npm install
- Set the following environment variables:
- REACT_APP_API_ADDRESS=example.com:1234 (this is the public address of where your
api
server will be) - REACT_APP_KATNIP_ADDRESS=katnip.kaspanet.org
- REACT_APP_KASPA_LIVE_ADDRESS=kaspa.live
- REACT_APP_API_ADDRESS=example.com:1234 (this is the public address of where your
- Within the
web
directory, run:npm run build
- Copy the entire
web
directory to wherever you wish to run theweb
server from
- Make sure the nodejs build environment is set up by running
- Run
processing
- Navigate to wherever you copied
kgi-processing
anddatabase
to - Set the following environment variables:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=database-name
- POSTGRES_HOST=database.example.com
- POSTGRES_PORT=5432
- Run:
kgi-processing --connection-string=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable
- Navigate to wherever you copied
- Run
api
- Navigate to wherever you copied
api
to - Run:
npm run start
- Navigate to wherever you copied
- Run
web
- Navigate to wherever you copied
web
to - Run:
npm install -g serve
- Set the WEB_PORT environment variable to the port you wish to serve the KGI UI from
- Run:
serve --listen=${WEB_PORT}
- Navigate to wherever you copied