TheGraph, a decentralized protocol for indexing and querying chain data, supports the Matic chain. Data defined through subgraphs is easy to query and explore. Subgraphs can be created locally, or use a free hosted explorer for indexing and data display.
Note: See https://thegraph.com/docs/quick-start for more details, local installation and more. The docs include an example for learning how subgraphs work and this video provides a good introduction.
Go to Graph Explorer (https://thegraph.com/explorer/) and setup an account. You will need a GitHub account for authentication.
Go to your dashboard and click Add Subgraph. Define the subgraph Name, Account, and Subtitle and update the image and other info (you can update later) if desired.
- Install Graph CLI on your machine (using either npm or yarn)
- The following command creates a subgraph that indexes all events of an existing contract. It attempts to fetch the contract ABI from BlockScout and falls back to requesting a local file path. If any of the optional arguments are missing, it takes you through an interactive form.
Note: More details are here: https://thegraph.com/docs/define-a-subgraph#create-a-subgraph-project
- Authenticate with the hosted service
You can find the access token by going to your dashboard on the graph website.
cd to the directory you created and start defining the subgraph. Information on creating a subgraph is available in the Graph Docs here. https://thegraph.com/docs/define-a-subgraph
When you are ready, deploy your subgraph. You can always test and redeploy as needed.
If your previously deployed subgraph is still in status Syncing, it will be immediately replaced with the newly deployed version. If the previously deployed subgraph is already fully synced, Graph Node will mark the newly deployed version as the Pending Version, sync it in the background, and only replace the currently deployed version with the new one once syncing the new version has finished. This ensures that you have a subgraph to work with while the new version is syncing.
Your subgraph will be deployed and can be accessed from your dashboard.
You can learn about querying the subgraph here: https://thegraph.com/docs/query-the-graph#using-the-graph-explorer
If you want to make your subgraph public, you can do so by accessing your subgraph from your dashboard and then click on edit button. You will see the slider at the bottom of edit page.