- Set up your subgraph by adding it to the Chainstack console, configuring it via Graph CLI (install, init, build), and deploying it with the provided deployment command.
- Configure
schema.graphql
andsubgraph.yaml
carefully to define the desired indexing entities and starting block. - Track deployment status in the console (sync in progress, up to date, or failed) and use logs for troubleshooting.
- Query your subgraph using either the CLI’s Query URL or the GraphQL UI URL to seamlessly fetch on-chain data.
Set up a subgraph
To set up a subgraph, complete the following steps:Add a subgraph
Subgraphs are available starting from the paid plans with the pay-as-you-go setting enabled.Subgraphs are billed at $0.10 per hour plus 20 request units per request.
- Click Add subgraph. The Add subgraph page is displayed.
-
In the Choose network section:
- Choose a Blockchain protocol.
- Choose the Network. Currently, Mainnnet is supported.
- Choose the Type.
- Click Next. The Create subgraph section is displayed.
-
In the Create subgraph section:
- Enter a Name for the subgraph.
- Select the Project that you want to assign your subgraph to.
- Click Add subgraph. The details page of the new subgraph is displayed.
Create and configure a subgraph
Before you begin: you must have Graph CLI installed globally to build and deploy subgraphs. You can install it with npm as follows:-
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:
Deploy a 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:
If the subgraph is in the Failed state, click Logs to view four levels of messages generated by the indexer and troubleshoot the issue.
Query a subgraph
To query a subgraph, you can choose from either of the following Subgraph query options in the subgraph details page:- Query URL — use this URL to query in the CLI.
- GraphQL UI URL — use this URL to query in the GraphQL UI.