Deploying subgraph on Ubuntu 18.04
How to deploy a subgraph on VPS
by Ivan#7522 (Discord)
This step-by-step guide describes how to deploy an example subgraph on a VPS with Ubuntu 18.04. After deploying an example, you can play around with it, make changes is mappings, schema, etc. Since some users (including myself) have encountered many difficulties, this guide focuses on all steps, performing which, you will be able to deploy your subgraph flawlessly.
First, you need to get a VPS. Go to Hetzner Cloud (referral link will grant you 20$ bonus). Choose a server (2 CPU will be OK) and operating system (Ubuntu 18.04). When you deploy a server, IP and password will be sent to your e-mail.
In Terminal (standart on mac, or iTerm, or any else), type
Change <IP> to the IP of your server, press enter and enter your password.
Next, you will need to update and install things like git, yarn and nvm.
sudo apt update
sudo apt upgrade
sudo apt install git
git config — global user.name “your-github-username”
git config — global user.email “your-github-email”
Installing nodejs and npm
curl -sL https://deb.nodesource.com/setup_14.x | \sudo -E bash — && \
sudo apt install -y nodejs && sudo npm install -g npm@latest
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
nvm install 14.15.1
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
Now you have completed all possible requirements and we can move on to deploying a subgraph.
Go to https://thegraph.com/explorer/dashboard and login, using your github account. Go to dashboard an click “Add subgraph”.
Fill in all the fields and click “Create subgraph”.
Now you can see an instruction, which we will walkthrough, access token, which we will need later and current status — undeployed.
In order to deploy subgraph, enter in your terminal:
yarn global add @graphprotocol/graph-cli
graph init --from-example <your-github-username>/<subgraph-name>
Change <your-github-username>/<subgraph-name> to your data. I am using Ivan123-ops/Tbtcgraph here.
Next, find the access token in Graph Dashboard (mentioned before) and type in your terminal:
yarn codegengraph deploy --access-token <your-access-token> \
--node https://api.thegraph.com/deploy/ \
--ipfs https://api.thegraph.com/ipfs/ \
Change <subgraph-name> to your subgraph name and <your-access-token> to access token found in dashboard. Also don’t forget to change <your-github-username>/<subgraph-name>.
If you see this message, you have successfully deployed your subgraph!
Navigate to Graph Dashboard, where you will see that your subgraph is deployed and synced. Now you can start experimenting on it.
If you have questions, contact me via Discord Ivan#7522