This is a backend for the PKT block explorer, it implements two APIs. API v0 is based based on the BitCore Node API but with some features added and others changed or removed. API v1 is an evolution of API v0 with additional features and more standardized URL structure.
- pkt-cash/pkt-explorer is the best frontend for this block explorer server, it is the most up to date.
- cjdelisle/pkt-insight-fe is a second frontend which is forked from the Bitcore Insight project. This package does not work quite as well as the original Bitcore Insight codebase and should be considered only as a prototype.
This backend is based on the ClickHouse database which is not only
blazing fast for the analytical type workloads typical of a block explorer, but also allows for the
creation of
Materialized Views,
which allow the aggregation of data in real time as the data is received. For example, the /richlist
endpoint which computes balances of all active addresses in the blockchain takes 5 minutes and 16
seconds to compute using Bitcore's MongoDB database so it can only reasonably be run periodically,
leading to stale data. Even with ClickHouse it takes 9 seconds to compute the rich list, much better
but still far too much to wait for a page to load. But, using a Materialized View, the data can be
aggregated in real time as each new block is discovered, allowing the data to be always up to date
and instantly accessible.
- Login to your server, these instructions assume you're using Fedora33 with tmux
- Get in the tmux, create a new window
ctrl+b c
- Install docker https://docs.docker.com/engine/install/fedora/ (don't use the version from the OS)
- install nodejs, git, and golang
dnf install nodejs git golang
- startup docker
service docker start
- Start
sudo systemctl start docker
- Start
- add a user called
explorer
and with UID 101 (useradd --uid 101 explorer
)- Using uid 101 will allow clickhouse docker to access the user's home directory
- open a new window in tmux, name it pktd
su explorer
to change user- Install pktd https://docs.pkt.cash/en/latest/pktd/
- Make a new folder called clickhouse_data, this will be used later
mkdir ~/clickhouse_data
- Compile pktd
cd pktd
./do
- Launch pktd with
./bin/pktd -ux -Px --txindex
and leave it in that window to sync
- make a new window, name it clickhouse-server
- Launch clickhouse
docker run -it -p localhost:8123:8123 --rm --name clickhouse-server --label=disable --ulimit nofile=262144:262144 --volume=/home/explorer/clickhouse_data:/var/lib/clickhouse -e CLICKHOUSE_PASSWORD=password yandex/clickhouse-server
- Launch clickhouse
- make a new window, call it clickhouse-client
- launch clickhouse client
docker exec -it clickhouse-server clickhouse-client --password=password
- You should see a prompt like the following
32d4f36b8fe1 :)
- In this window, you will be able to query the db
- launch clickhouse client
- Create a new window, call it syncer
su explorer
cd ~
git clone https://github.com/pkt-cash/pkt-explorer-backend
cd pkt-explorer-backend
npm install
cp config.example.js config.js
- launch syncer:
node ./syncer.js --chain PKT/pkt
- check that it seems to be adding the blockchain to clickhouse
- Create a new window, call it server
su explorer
- launch server:
node ./server.js --port 3002
- Return to a bash window
- check the server is running:
curl localhost:3002/api/v1/status/enabled-chains
- Should say PKT chain is enabled
- check the server is connecting to the db
curl localhost:3002/api/v1/PKT/pkt/chain/down/1/1
- Should provide block information about a past block
- check the server is running:
You can find documentation on the API versions in the /docs folder:
This project is designed to be portable to any bitcoin-like blockchain. It is somewhat reliant on additional features to the RPC which are provided by pktd, but pktd itself is based on btcd and support for bitcoin and bitcoin testnet are still present. The best way to get this project working on another bitcoin-based blockchain is as follows:
- Add the coin to pktd, note how --btc and --testnet are selected and follow this model
- Update lib/rewards.js to include the mining payout model for the blockchain you are adding
- Launch the backend syncer and server using your chain
- Launch the frontend and begin testing
- Please make relevant pull requests
This project is may be used and copied in accordance with the terms of the MIT license.
The development has been funded by the PKT Block Explorer Project