TheGraph Data Indexing
TheGraph, a decentralized protocol for indexing and querying chain data, supports the xDai 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.

Setting up a hosted project with TheGraph & xDai

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.
The article below also covers the initializing a graph using a smart contract address on xDai.
Impact insights
Medium

Steps:

1) Go to Graph Explorer (https://thegraph.com/explorer/) and setup an account. You will need a GitHub account for authentication.
2) 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.
Basic info is required to create a subgraph. You can modify later if needed.
3) Install Graph CLI on your machine (using either npm or yarn)
1
$ npm install -g @graphprotocol/graph-cli
2
$ yarn global add @graphprotocol/graph-cli
3
Copied!
4) 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: The interactive form does not currently include xDai in the dropdown of networks, so using the following flags is useful for an xDai deployment
1
graph init \
2
--from-contract <CONTRACT_ADDRESS> \
3
[--network xdai ] \
4
[--abi <FILE>] \
5
<GITHUB_USER>/<SUBGRAPH_NAME> [<DIRECTORY>]
Copied!
--from-contract <CONTRACT_ADDRESS> is the address of your existing contract.
--abi <FILE> is a local path to a contract ABI file (optional, If verified in BlockScout, the graph will grab the ABI, otherwise you will need manually add the ABI. You can save the abi from BlockScout or by running truffle compile or solc on a public project. More info available here.)
The <GITHUB_USER> is your github user or organization name, <SUBGRAPH_NAME> is the name for your subgraph, and <DIRECTORY> is the optional name of the directory where graph init will put the example subgraph manifest.
  • Chose the subgraph name created in step 2 as lowercase-hypenated
5) Authenticate with the hosted service
1
graph auth https://api.thegraph.com/deploy/ <your-access-token>
Copied!
6) cd to the directory you created and start defining the subgraph. Information on creating a subgraph is available in the Graph Docs.
Define a Subgraph | Graph Docs
7) When you are ready, deploy your subgraph. You can always test and redeploy as needed.
1
yarn deploy
Copied!
Your subgraph will be deployed, and you can try sample queries. If you are ready to make it public, select the subgraph and turn off the Hide slider.
Last modified 4mo ago