Skip to content

Instantly share code, notes, and snippets.

@novy4
Last active February 21, 2021 08:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save novy4/5272d51872d4a895bf8f76412edc3f04 to your computer and use it in GitHub Desktop.
Save novy4/5272d51872d4a895bf8f76412edc3f04 to your computer and use it in GitHub Desktop.
#####GRAPH-NODE######
#####NPM INSTALL#####
sudo apt update && \
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash - && \
sudo apt -y install nodejs && \
sudo apt install -y libsecret-1-dev && \
nodejs -v && \
npm version
####DATABASE-SERVER##################
####CREATE DATABASE FOR INDEXER####
sudo -i -u postgres
createdb graph-indexeragent
exit
exit
######################################
####AGENT & SERVICE INSTALL####
npm set registry https://testnet.thegraph.com/npm-registry/ && \
npm login
##enter login, pass and email
npm install -g @graphprotocol/indexer-agent \
npm install -g @graphprotocol/indexer-service \
npm install -g @graphprotocol/indexer-cli \
npm install -g -f @graphprotocol/graph-cli@0.19.0-alpha.0 ###
####ADDING SERVICES############
export ETHEREUM_RPC=https://rinkeby.infura.io/v3/uniq-code
export INDEXER_URL=$(curl -s ifconfig.me)
export SERVER_HOST=ip
export SERVER_PORT=5432
export SERVER_DB_NAME=graph-indexeragent
export SERVER_DB_USER=postgres
export SERVER_DB_PASSWORD=password
export MNEMONIC='12 words'
sudo ### IF NOT UNDER ROOT
## --indexer-geo-coordinates #Helsinki: 60.16952 24.93545, Filkenstein: 49.101719 12.494180
###COPY FROM HERE###
sudo tee /etc/systemd/system/graph-indexer-agent.service &>/dev/null <<EOF
[Unit]
Description=Graph Chain Indexer Agent
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User=$(id -u -n)
Restart=always
RestartSec=1
ExecStart=/usr/bin/graph-indexer-agent start \
--graph-node-query-endpoint http://localhost:8000/ \
--graph-node-admin-endpoint http://localhost:8020/ \
--graph-node-status-endpoint http://localhost:8030/graphql \
--public-indexer-url http://$INDEXER_URL/ \
--indexer-management-port 18000 \
--indexer-geo-coordinates 60.16952 24.93545 \
--postgres-host $SERVER_HOST \
--postgres-port $SERVER_PORT \
--postgres-database $SERVER_DB_NAME \
--postgres-username $SERVER_DB_USER \
--postgres-password $SERVER_DB_PASSWORD \
--index-node-ids default \
--network-subgraph-endpoint https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-rinkeby \
--ethereum $ETHEREUM_RPC \
--mnemonic "$MNEMONIC"
[Install]
WantedBy=multi-user.target
EOF
sudo tee /etc/systemd/system/graph-indexer-service.service &>/dev/null <<EOF
[Unit]
Description=Graph Chain Indexer Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User=$(id -u -n)
Restart=always
RestartSec=1
Environment="SERVER_HOST=$SERVER_HOST"
Environment="SERVER_PORT=$SERVER_PORT"
Environment="SERVER_DB_NAME=$SERVER_DB_NAME"
Environment="SERVER_DB_USER=$SERVER_DB_USER"
Environment="SERVER_DB_PASSWORD=$SERVER_DB_PASSWORD"
ExecStart=/usr/bin/graph-indexer-service start \
--port 80 \
--graph-node-query-endpoint http://localhost:8000/ \
--network-subgraph-endpoint https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-rinkeby \
--graph-node-status-endpoint http://localhost:8030/graphql \
--ethereum $ETHEREUM_RPC \
--mnemonic "$MNEMONIC"
[Install]
WantedBy=multi-user.target
EOF
###COPY TILL HERE###
sudo systemctl daemon-reload
sudo systemctl start graph-indexer-agent
sudo systemctl start graph-indexer-service
sudo systemctl enable graph-indexer-agent
sudo systemctl enable graph-indexer-service
sudo journalctl -u graph-indexer-agent -f
sudo journalctl -u graph-indexer-service -f
####INDEXER CLI####
graph indexer connect http://localhost:18000/
graph indexer status
####CLI ADD RULES ####
graph indexer rules always Qme2hDXrkBpuXAYEuwGPAjr6zwiMZV4FHLLBa3BHzatBWx
graph indexer rules always QmXKwSEMirgWVn41nRzkT3hpUBw29cp619Gx58XW6mPhZP
graph indexer rules always QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9
graph indexer rules start Qme2hDXrkBpuXAYEuwGPAjr6zwiMZV4FHLLBa3BHzatBWx
graph indexer rules start QmXKwSEMirgWVn41nRzkT3hpUBw29cp619Gx58XW6mPhZP
graph indexer rules start QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9
graph indexer rules always global
graph indexer rules set Qme2hDXrkBpuXAYEuwGPAjr6zwiMZV4FHLLBa3BHzatBWx allocationAmount 100
graph indexer rules set QmXKwSEMirgWVn41nRzkT3hpUBw29cp619Gx58XW6mPhZP allocationAmount 100
graph indexer rules set QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9 allocationAmount 100
graph indexer status
### Please wait while all endpoints will be up!
https://airtable.com/shrTnJukfu2jArJnN
####PRMETHEUS METRICS########
nano /etc/prometheus/prometheus.yml
- job_name: 'graph-indexer-service'
static_configs:
- targets: [localhost:7300]
sudo systemctl restart prometheus
sudo ufw allow 80/tcp
tips:
- IF you have a problem running nodejs on port 80: sudo setcap 'cap_net_bind_service=+ep' `which node`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment