> For the complete documentation index, see [llms.txt](https://killswitchofficial.gitbook.io/rei-chain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://killswitchofficial.gitbook.io/rei-chain/developer/subgraph.md).

# SubGraph

Developers can create their own SubGraph and create a pull-request of their ipfs\_hash and deployed.

## REI GraphQL

REI has provided The Graph, a decentralized protocol for indexing and querying data from blockchains.

Endpoint: <https://rei-graph.moonrhythm.io/>

To learn more about The Graph, [here](https://thegraph.com/docs/en/about/introduction/) is the official document.

### Pre-requisite

* [The Graph CLI](https://thegraph.com/docs/en/developer/quick-start/): `npm install -g @graphprotocol/graph-cli`
* [IPFS](https://ipfs.io/): A peer-to-peer hypermedia protocol designed to preserve and grow humanity's knowledge by making the web upgradeable, resilient, and more open.

### Get Started

Init graph from contract

```
graph init --product hosted-service --from-contract 0xC437190E5c4F85EbBdE74c86472900b323447603
```

* Protocol - ethereum
* Name - In format `[group]/[name]` It will be part of endpoint `/name/foodcourt/factory/`
* Ethereum network - any (will edit later)

After successfully generate the project, the following structure are generated

```
- abis
- src
    - mapping.ts
- package.json
- schema.graphql
- subgraph.yaml
- tsconfig.json
```

#### Replace network value

{% hint style="info" %}
network should be **`rei`**
{% endhint %}

{% code title="subgraph.yaml" %}

```
specVersion: 0.0.2
schema:
  file: ./schema.graphql
dataSources:
  - kind: ethereum
    name: FoodcourtFactory
    network: rei
    source:
      address: '0xC437190E5c4F85EbBdE74c86472900b323447603'
      abi: FoodcourtFactory
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.5
      language: wasm/assemblyscript
      entities:
        - PairCreated
      abis:
        - name: FoodcourtFactory
          file: ./abis/FoodcourtFactory.json
      eventHandlers:
        - event: PairCreated(indexed address,indexed address,address,uint256)
          handler: handlePairCreated
      file: ./src/mapping.ts

```

{% endcode %}

Run `codegen` to get `generated` folder

```
npm run codegen
```

Run `build` and upload to ipfs server to get `hash`

```
graph build --ipfs http://localhost:5001 subgraph.yaml

Build completed: Qm____HASH____
```

Next, create a pull-request to <https://github.com/moonrhythm/rei-graph>

[example](https://github.com/moonrhythm/rei-graph/blob/e9073cae6efd69299ab7fe695798d3482d6eb5d8/subgraph/foodcourt-factory.yaml)

![](https://3025600752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ml8SQ6kky6AssiRXmZI%2Fuploads%2FWWa4BBVukg6M3cOBcH6z%2FScreen%20Shot%202565-01-27%20at%2011.55.36.png?alt=media\&token=1eea1368-08d6-429e-bdb0-6a077fd4a88f)

After deploy and indexing is done, you should get endpoint like this to query your analytics data

<https://rei-graph.moonrhythm.io/subgraphs/name/foodcourt/factory/graphql>
