项目作者: Colm3na

项目描述 :
PolkaStats Next Gen
高级语言: Vue
项目地址: git://github.com/Colm3na/polkastats-ng.git
创建时间: 2021-01-29T10:10:50Z
项目社区:https://github.com/Colm3na/polkastats-ng

开源协议:Apache License 2.0

下载


PolkaStats

Polkastats is a block explorer for Polkadot, Kusama and other blockchains based on Substrate framework.

Check it out live versions:

Install

Dependencies

In Ubuntu 20.04 server you can do:

  1. apt update && apt upgrade -y && apt auto-remove
  2. apt install git build-essential apt-transport-https ca-certificates curl software-properties-common libpq-dev gnupg
  3. # docker
  4. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
  5. add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
  6. apt update
  7. apt install docker-ce
  8. # docker-compose
  9. sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  10. chmod +x /usr/local/bin/docker-compose
  11. # node v16
  12. mkdir -p /etc/apt/keyrings
  13. curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
  14. NODE_MAJOR=16
  15. echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
  16. apt-get update
  17. apt-get install nodejs -y
  18. # yarn
  19. npm install --global yarn

Mono repo

Clone Polkastats repository and install js dependencies:

  1. cd /usr/local/
  2. git clone https://github.com/polkastats/polkastats.git
  3. cd polkastats
  4. yarn

Backend

Before build dockers we need to copy and edit an .env file:

  1. cp backend/.env-sample backend/.env

NOTE: change Hasura password in HASURA_GRAPHQL_ADMIN_SECRET environmment variable. Also you can add your Sentry instance URL.

Polkadot:

  1. yarn workspace backend docker:polkadot

Or Kusama:

  1. yarn workspace backend docker:kusama

That will build and start all the required dockers:

  • PostgreSQL
  • Hasura GraphQL server
  • Parity Polkadot client
  • Node.js crawler
  • Substrate API Sidecar

Hasura console

After that you can access to Hasura console at http://server_ip_address:8082 and login as admin using the password you previously set in HASURA_GRAPHQL_ADMIN_SECRET environment variable.

Nginx configuration

You can use Nginx as a inverse proxy for Hasura GraphQL and also to serve the static frontend.

Example nginx config /etc/nginx/sites-available/default with SSL enabled using Certbot:

  1. server {
  2. root /usr/local/polkastats-ng/frontend/dist;
  3. index index.html index.htm index.nginx-debian.html;
  4. server_name yourdomain.io;
  5. location / {
  6. try_files $uri $uri/ /index.html;
  7. }
  8. location /graphql {
  9. proxy_pass http://localhost:8082/v1/graphql;
  10. proxy_http_version 1.1;
  11. proxy_set_header Upgrade $http_upgrade;
  12. proxy_set_header Connection "upgrade";
  13. }
  14. location ~ ^/api/ {
  15. proxy_pass http://localhost:8000;
  16. proxy_http_version 1.1;
  17. proxy_set_header Upgrade $http_upgrade;
  18. proxy_set_header Connection "upgrade";
  19. }
  20. listen [::]:443 ssl ipv6only=on; # managed by Certbot
  21. listen 443 ssl; # managed by Certbot
  22. ssl_certificate /etc/letsencrypt/live/yourdomain.io/fullchain.pem; # managed by Certbot
  23. ssl_certificate_key /etc/letsencrypt/live/yourdomain.io/privkey.pem; # managed by Certbot
  24. include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  25. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  26. }
  27. server {
  28. if ($host = yourdomain.io) {
  29. return 301 https://$host$request_uri;
  30. } # managed by Certbot
  31. listen 80 default_server;
  32. listen [::]:80 default_server;
  33. server_name yourdomain.io;
  34. return 404; # managed by Certbot
  35. }

Apply your new configuration:

  1. ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
  2. systemctl restart nginx

Frontend

First, copy the frontend config file either for Kusama:

  1. cp frontend/frontend.config-kusama.js frontend/frontend.config.js

Or Polkadot:

  1. cp frontend/frontend.config-polkadot.js frontend/frontend.config.js

Start a dev frontend with hot reload at http://localhost:3000

  1. yarn workspace frontend dev

Generate a static build under frontend/dist directory:

  1. yarn workspace frontend generate

Filter outside connections to RPC

  1. /sbin/iptables -A INPUT -p tcp -i <put_your_internet_interface_here> --dport 9944 -j DROP