KGI is comprised of four components:
- A postgres database
- A
processingkaspa node (this is simply a kaspad wrapped in some extra logic) - An
apiREST server - A
webserver
How the components interact:
- The
processingnode 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
webserver listens to http requests on some port - When a user navigates their browser to that port, the
webserver serves the KGI clientside logic, which includes the UI - The clientside logic calls the
apiREST server every so often - The
apiREST server queries the postgres database and returns it to the clientside - The clientside uses the response it received from the
apiREST 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
processingdirectory, editgo.mod:- Delete the line that starts with
replace github.com/kaspanet/kaspad - Set your desired kaspad version in the line under
requirethat starts withgithub.com/kaspanet/kaspad
- Delete the line that starts with
- Within the
processingdirectory, rungo build -o kgi-processing .. This will produce an executable file namedkgi-processing - Copy
kgi-processinganddatabasedirectory (also within theprocessingdirectory) 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
apidirectory, run:npm install - Copy the entire
apidirectory to wherever you wish to run theapiserver 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
webdirectory, run:npm install - Set the following environment variables:
- REACT_APP_API_ADDRESS=example.com:1234 (this is the public address of where your
apiserver will be) - REACT_APP_EXPLORER_ADDRESS=explorer.kaspa.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
webdirectory, run:npm run build - Copy the entire
webdirectory to wherever you wish to run thewebserver from
- Make sure the nodejs build environment is set up by running
- Run
processing- Navigate to wherever you copied
kgi-processinganddatabaseto - 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
apito - Run:
npm run start
- Navigate to wherever you copied
- Run
web- Navigate to wherever you copied
webto - 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