- 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.graphqlandsubgraph.yamlcarefully 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
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: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.
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: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:
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:
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.