> For the complete documentation index, see [llms.txt](https://docs.lumia.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lumia.org/build-on-lumia/indexers/index-contract-events-with-the-graph.md).

# Index contract events with The Graph

You want to index contract events on Lumia so your app can query historical/aggregated data instead of scanning logs itself.

**Who this is for:** developers who need indexed, queryable contract data. **Prerequisites:** a deployed, verified contract on Lumia; [Networks & Endpoints](https://app.gitbook.com/s/chmhPiVNAafGw48c4oU2/reference/networks-and-endpoints).

### Steps (confirm network support before deploying)

{% stepper %}
{% step %}
**Install the Graph CLI**

Consult The Graph's own current published docs for the package name and version; that's their product, not Lumia's.
{% endstep %}

{% step %}
**Scaffold a subgraph against your contract's ABI and address**

```bash
graph init --from-contract 0xYourContractAddress --abi ./YourContract.json
```

When prompted for the network, you need Lumia's network identifier as registered with The Graph.
{% endstep %}

{% step %}
**Define events and handlers**

Define the events you want indexed in `schema.graphql` and the corresponding handlers in the generated mapping file (AssemblyScript).
{% endstep %}

{% step %}
**Deploy**

Deploy to a self-hosted Graph Node pointed at Lumia's RPC (see [`/reference/networks`](https://app.gitbook.com/s/chmhPiVNAafGw48c4oU2/reference/networks-and-endpoints)), or to The Graph's hosted/network service if Lumia is a supported network there.
{% endstep %}
{% endstepper %}

### Verify it worked

Query the deployed subgraph's GraphQL endpoint for an entity you know exists on-chain (e.g. a specific event from a transaction you already confirmed on the explorer) and confirm the response matches.

```graphql
{
  yourEntities(first: 5, orderBy: blockNumber, orderDirection: desc) {
    id
    blockNumber
  }
}
```

### Troubleshooting

<details>

<summary><code>graph init</code> has no Lumia network option</summary>

This is expected until network registration is confirmed; fall back to a self-hosted Graph Node against Lumia's RPC.

</details>

<details>

<summary>Subgraph syncs but returns no entities</summary>

Check your handler's event signature against the contract's actual emitted event. A mismatched ABI is the most common cause.

</details>
