KGI is comprised of four components:
- A postgres database
- A
processingserver connected to a kaspa node via gRPC - An
apiREST server - A
webserver
How the components interact:
- The
processingserver connects as a gRPC client to a Kaspa node - It queries all blocks since the pruning point and subscribes to all block added and VSPC changes
- 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_PORT=5433
- KGI_NETWORK=testnet - accepted values ["", "testnet", "simnet", "devnet"]
- KGI_NETWORK_SUFFIX=12 - only if KGI_NETWORK=="testnet"
- API_PORT=4575
- WEB_PORT=8080
- KASPA_LIVE_ADDRESS=localhost
- EXPLORER_ADDRESS=explorer.kaspa.org - adapt to the network type
- 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 - this is the address of a public explorer able to display block properties
- REACT_APP_KASPA_LIVE_ADDRESS=kaspa.live - this is the public address of where your
webserver will be
- 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
- KGI_RPCSERVER=localhost
- KGI_NETWORK_ARGS="--testnet --netsuffix=12" (optional) - this defines the network type (so leave it undefined/unset for mainnet)
- Run:
kgi-processing --connection-string=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable --rpcserver=${KGI_RPCSERVER} ${KGI_NETWORK_ARGS}
- Navigate to wherever you copied
- Run
api- Navigate to wherever you copied
apito - Set the following environment variables:
- POSTGRES_USER=username - which is the username for database connection.
- POSTGRES_PASSWORD=password - which is the password for database connection.
- POSTGRES_DB=database-name - which is the database to be used.
- POSTGRES_HOST=database.example.com (optional) - which is the host of the database server (default: localhost).
- POSTGRES_PORT=5432 (optional) - which is the port for database connection (default: 5432).
- 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