Create a Subgraph
This section covers what is a subgraph, why should you care about it, and how to create one.
Last updated
This section covers what is a subgraph, why should you care about it, and how to create one.
Last updated
A subgraph is a custom schema for indexing blockchain data. It provides efficient access to data and allows easy querying via GraphQL.
Subgraphs have several advantages over traditional RPC endpoints:
Faster querying: Subgraphs are designed for efficient querying, allowing for faster data retrieval and processing.
Lightweight API: By providing a GraphQL API, subgraphs reduce the complexity of querying blockchain data.
Customizable schema: Developers can create a schema that specifically fits their needs, making it easier to work with blockchain data.
Cost-effective: Subgraphs are more cost-effective than running archival nodes or parsing entire blockchain histories.
If you're interested in learning more about subgraphs, we recommend checking out for a comprehensive guide on how to develop a subgraph.
To create a subgraph, you need to follow these steps:
Once you have registered your subgraph, you'll be presented with detailed instructions on how to deploy it. A brief summary:
Install prerequisites: , , , and .
Build the subgraph (as an exercise, you can use ):
Deploy the subgraph using the following command. You'll be presented with specific values for the GRAPH_INDEX_URI
and GRAPH_IPFS_URI
parameters. Make sure to replace <YOUR_API_KEY>
with your actual API key.
To query your subgraph, you can use the playground provided by Proteus Shield:
Go to the Subgraphs tab.
Find and select the subgraph you wish to query.
In the Playground area, click the Show GraphiQL Explorer button (represented by a folder icon).
Select the elements you want to query and modify the query as needed.
Click Execute query to run the query.
To query your subgraph from your code, send a POST request to the GraphQL endpoint specified in the subgraph details under Queries (HTTP)
.
The resulting query may look like the following (based on subgraph):