# Subgraphs

Shadow RPCs support the read methods required by most subgraph services.

You can run a local subgraph pointed to a Shadow RPC today, and we're actively working on integrations with hosted subgraph providers.

## Why use Shadow with subgraphs?

You can significantly reduce the time to resync your subgraph by moving pieces of indexing logic into custom shadow events. For example, if your subgraph currently:

* Uses bindings to call contract view functions for state data
* Uses any `callHandlers`&#x20;
* Recreates contract logic in AssemblyScript to arrive at required values

Then you'll be able to make your subgraph sync much faster with Shadow.

Instead of making slow and expensive RPC calls, relying on function tracing, or writing complex logic in AssemblyScript, you can move everything into simple `eventHandlers` with custom shadow events.

{% hint style="info" %}
Moving indexing logic into Solidity also makes your subgraph more end-to-end testable, reducing the engineering time for releasing new features and debugging indexing problems.
{% endhint %}

Our team can pair with you to evaluate potential subgraph performance improvements. If you're interested in getting direct support from our engineering team on this, please email <fast@shadow.xyz>.

## Integrations

### Local Graph Node

{% hint style="info" %}
Configure your local node to use your Shadow RPC URL as a provider for your desired chain and include your Shadow API key as part of the provider details by using the \`X-SHADOW-API-KEY\` custom header.\
\
For more info, see The Graph's documentation on [local Graph Node configuration](https://github.com/graphprotocol/graph-node/blob/master/docs/config.md#configuring-chains).
{% endhint %}

Step-by-step instructions on setting up a local graph node pointed to your Shadow RPC.

1. [Spin up](https://github.com/graphprotocol/graph-node?tab=readme-ov-file#command-line-interface) a local graph node instance; requirements:&#x20;
   * [Shadow fork](https://www.shadow.xyz/) URL
   * Local [IPFS](https://explore.ipld.io/) instance
   * [Postgres](https://www.postgresql.org/) access (local/remote)
   * Graph [CLI](https://www.npmjs.com/package/@graphprotocol/graph-cli)&#x20;
2. Migrate your shadow contracts to a local solidity project where you can compile the base contract as well as generate respective ABI bindings (e.g. Foundry, Hardhat)
3. [Initialize](https://thegraph.com/docs/en/developing/creating-a-subgraph/#from-an-existing-contract) subgraph project using your local shadow contract instead of pointing to an Etherscan explorer
4. Verify that your subgraph.yaml [manifest](https://thegraph.com/docs/en/developing/creating-a-subgraph/#the-subgraph-manifest):
   * Points to the appropriate local contract dependencies (i.e, abi.json, source path)
   * Contains the shadow events in the `eventHandlers` mapping
   * Uses the correct onchain address&#x20;
5. Create and deploy your local subgraph to your local node; e.g:
   * graph create --node [http://127.0.0.1:8020](http://127.0.0.1:8020/) SUBGRAPH\_NAME
   * graph deploy SUBGRAPH\_NAME --ipfs [http://127.0.0.1:5001](http://127.0.0.1:5001/) --node <http://127.0.0.1:8020>
6. Verify that your shadow logs are being indexed by verifying your postgres db. There should be sgd\* database schema with unique tables per each contract event id. (e.g, sgd0/transfer)

<figure><img src="/files/r5F8CKdyUlLsxioY3fuN" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shadow.xyz/product-guide/subgraphs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
