How to Build a Subgraph via Contract on Windows for a Non-Tech Curators
In order to use hosting from the Schedule team, you need to go through authorization on their website (authorization is possible through your Github account, so if you don’t have one, first create it). After authorization, you will be able to add new Subgraphs.
Create a subgraph in The Graph Explorer
This is the first step: sign in to The Graph explorer with your Github account and click on ‘Add subgraph’
then you will need to fill the fields to create your subgraph.
Once you’re ready to deploy your Subgraphs to the Hosted Service, remember
· Image: Incorporating a representative image for it (600x600, .png file)
· Subgraph Name: This will be the main name of the subgraph, used also in the URL link. You should avoid using “subgraph” in the name, as that is already implied.
· Account: If you are participating as a team, consider using your team’s GitHub account
· Subtitle: a short explanation about what your subgraph does
· Description: A good description of what the subgraph does
· GitHub URL: link to the GitHub repository where the code is hosted (remember to set the repository as public)
· Hide: very useful for test subgraph
After clicking on ‘Create subgraph’, we will be reaching the following screen with 3 needed steps before being able to deploy our subgraph
To prepare an installation subgraph, you need to have:
· Node.js (https://nodejs.org/en/)
· Git for Windows (https://gitforwindows.org/)
· Yarn for Windows with the installer (https://classic.yarnpkg.com/en/docs/install/#windows-stable)
1. Install Graph CLI
This is the first step, and here we will need to deep dive into our operating system to install correctly the environment we need to be able to get Graph CLI going.
When you click on ‘Show commands’, we get:
We will need to have npm or/and yarn installed to be able to have Graph CLI running on our Windows computer.
First I would recommend using Microsoft PowerShell as an administrator to run your commands.
To be able to use PowerShell properly, you will need to give it the ability to execute scripts which is not by default. To do that, launch PowerShell as an administrator and run:
$ Set-ExecutionPolicy RemoteSigned
$ Set-ExecutionPolicy Unrestricted -scope Process
Each time you will need to confirm by tapping Y (for Yes).
In the PowerShell run:
$ npm install -g npm
You might need to upgrade your version. In this case run:
$ npm install -g npm-windows-upgrade
Below box 1, you will find a message suggesting that you install the Graph CLI using npm or yarn directly from your terminal window:
$ npm install -g @graphprotocol/graph-cli$ yarn global add @graphprotocol/graph-cli
Now that we have gone through all those steps, we can finally install Graph CLI.
2. Initiate the subgraph
Let’s move now to step 2.
To initiate the subgraph by going into the Nexo smart contract, which we will need to find out first. You can use Etherscan to find it.
Let’s head to Etherscan to find the Nexo contract address
Now that we have the address we can run the command:
$ graph init \ — from-contract 0xb62132e35a6c13ee1ee0f84dc5d40bad8d815206 /<Githubusername>/<Directory>
which will give in the MS PowerShell with my Github username and the directory I will create the subgraph in:
The subgraph is created. Now we need to deploy it. But before that, we will need to double-check the generated schema and mappings and update it with the correct fields and values.
3. Deploy the subgraph
First, we need to authenticate with The Graph hosted service to be able to deploy our subgraph. In this case, we need to run the following command:
$ graph auth https://api.thegraph.com/deploy/ <ACCESS_TOKEN>
We will gate the ACCESS TOKEN from our subgraph page in the Explorer:
Note! If after running the command on MS Powershell, you can got the following error:
When reading the error message, you will find the following: ‘The original error was: Cannot find module ‘Keytar’
Let’s install it than using this command:
$ npm install keytar
or
$ npm install –g keytar
Now, let’s run the command again.
the next step now would be to deploy the subgraph with the command:
$ graph deploy \
— debug \
— node https://api.thegraph.com/deploy/ \
— ipfs https://api.thegraph.com/ipfs/ \
<SUBGRAPH_NAME>
If you will have errors, you can do such next steps:
1. Go to the Directory where the subgraph is
$ cd <your created directory>
2. Run the command
$ yarn deploy
There we go the subgraph is syncing with the hosted service.
To check it we can go back to The Graph Explorer subgraph page where after synching we can see it in the Explorer list of subgraphs.
Conclusion
Here the following resources to understand what we need to do:
1. https://thegraph.com/docs is The Graph internal resources which help understand what we are talking about
2. https://www.youtube.com/watch?v=coa0Vw47qNc is a video from David Kajpust (from The Graph team) showing how to build a subgraph on Mac.
Good luck!