TLDR:
schema.graphql
and subgraph.yaml
carefully to define the desired indexing entities and starting block.To set up a subgraph, complete the following steps:
In Subgraphs, you can view a list of all existing subgraphs and can filter the view using the Protocol drop-down list. You can create a new subgraph using the Add subgraph button and view the details of a subgraph by clicking on the subgraph name.
Subgraphs must be associated with a project; if you don’t already have a project to add the subgraph to, see create a project.
To add a subgraph:
Click Add subgraph. The Add subgraph page is displayed.
In the Choose network section:
In the Create subgraph section:
The subgraph details page includes information such as the Owner, Creation date, Region, and Protocol. You can view the Metrics about the requests made in the subgraph, view the Subgraph Query URLs, and the Subgraph Deployment command, which you require to deploy the subgraph.
Before you begin: you must have Graph CLI installed globally to build and deploy subgraphs. You can install it with npm as follows:
To check if the Graph CLI was installed correctly, run:
To create and configure a subgraph:
Open a new directory in your terminal and run:
Configure all the required parameters that are displayed in the CLI. The Graph will download your smart contract’s ABI and install all the dependencies by running npm install
automatically.
Set up your schema.graphql
file to define all the entities and key-value pairs that you want to query.
Go to your manifest file (subgraph.yaml
) and make sure all the deployment parameters are correctly defined. We recommend that you only start indexing data from the block number of the first transaction that you want to track as this can save a lot of indexing time.
To generate AssemblyScript types for the entities defined in your schema file, in your root directory, run:
When your mappings file is configured, run:
When your subgraph compiles successfully, you are now ready to deploy your subgraph.
To deploy your new subgraph:
In Subgraphs, open the details page of your new subgraph and copy the Deployment command, which will have the following format:
Paste and run the command in your CLI.
Enter a version label for your subgraph (you can use any number/letter character combination). If the subgraph is successfully deployed, you will receive a response like the following example:
In the subgraph details page, the status of the subgraph will change to Deployed. Initial sync in progress and will continuously provide feedback on the progress of the synchronization process. When it completes, the status will change to Up to date.
If the subgraph is in the Failed state, click Logs to view four levels of messages generated by the indexer and troubleshoot the issue.
To query a subgraph, you can choose from either of the following Subgraph query options in the subgraph details page:
To query your subgraph in the CLI, copy the Query URL from the subgraph details page and add it to the query. For example, to query transactions:
To query the subgraph using the GraphQL UI, copy the GraphQL UI URL from the subgraph details page and paste it in your browser. The GraphQL UI is displayed, where you can enter the details of your query.
TLDR:
schema.graphql
and subgraph.yaml
carefully to define the desired indexing entities and starting block.To set up a subgraph, complete the following steps:
In Subgraphs, you can view a list of all existing subgraphs and can filter the view using the Protocol drop-down list. You can create a new subgraph using the Add subgraph button and view the details of a subgraph by clicking on the subgraph name.
Subgraphs must be associated with a project; if you don’t already have a project to add the subgraph to, see create a project.
To add a subgraph:
Click Add subgraph. The Add subgraph page is displayed.
In the Choose network section:
In the Create subgraph section:
The subgraph details page includes information such as the Owner, Creation date, Region, and Protocol. You can view the Metrics about the requests made in the subgraph, view the Subgraph Query URLs, and the Subgraph Deployment command, which you require to deploy the subgraph.
Before you begin: you must have Graph CLI installed globally to build and deploy subgraphs. You can install it with npm as follows:
To check if the Graph CLI was installed correctly, run:
To create and configure a subgraph:
Open a new directory in your terminal and run:
Configure all the required parameters that are displayed in the CLI. The Graph will download your smart contract’s ABI and install all the dependencies by running npm install
automatically.
Set up your schema.graphql
file to define all the entities and key-value pairs that you want to query.
Go to your manifest file (subgraph.yaml
) and make sure all the deployment parameters are correctly defined. We recommend that you only start indexing data from the block number of the first transaction that you want to track as this can save a lot of indexing time.
To generate AssemblyScript types for the entities defined in your schema file, in your root directory, run:
When your mappings file is configured, run:
When your subgraph compiles successfully, you are now ready to deploy your subgraph.
To deploy your new subgraph:
In Subgraphs, open the details page of your new subgraph and copy the Deployment command, which will have the following format:
Paste and run the command in your CLI.
Enter a version label for your subgraph (you can use any number/letter character combination). If the subgraph is successfully deployed, you will receive a response like the following example:
In the subgraph details page, the status of the subgraph will change to Deployed. Initial sync in progress and will continuously provide feedback on the progress of the synchronization process. When it completes, the status will change to Up to date.
If the subgraph is in the Failed state, click Logs to view four levels of messages generated by the indexer and troubleshoot the issue.
To query a subgraph, you can choose from either of the following Subgraph query options in the subgraph details page:
To query your subgraph in the CLI, copy the Query URL from the subgraph details page and add it to the query. For example, to query transactions:
To query the subgraph using the GraphQL UI, copy the GraphQL UI URL from the subgraph details page and paste it in your browser. The GraphQL UI is displayed, where you can enter the details of your query.