Core Subgraph
Create and deploy subgraphs
Developers can use a self-hosted subgraph to extract data from the Core blockchain, processing and storing it for consumption via GraphQL. Let's take a look at how we can create and deploy this powerful tool.
Important URLs
We'll be using some standard URLs throughout this guide, which it’ll help to review before getting started.
MainNet
TestNet
General Subgraph Setup Steps
Create Repository
To create your subgraph repository, follow the official guide from The Graph. In order to deploy onto the Core graph network, make sure to set your network name in subgraph.yaml
to core. Depending on your subgraph, there may be a few more changes to make. You’ll find additional details in the full example section below.
Create and Deploy
To create and deploy your subgraph, execute the following commands in your subgraph project repository.
The graph deploy
command should return the HTTP query URL for your subgraph, which you can integrate into your application as appropriate.
Example: Deploying a Uniswap V2 subgraph
Now that we understand the process, let's walk through a full example by setting up a Uniswap V2 subgraph on Core.
First, clone the Uniswap V2 subgraph repository, navigate to the project folder, then execute the following commands from that directory:
Now we'll make a few required changes to the subgraph.yaml and helpers.ts files:
subgraph.yaml:
Change network name to
core
on lines 9 and 37.Update the factory address on line 11.
Update the
startBlock
on line 13 to a reasonable block height (current block height available here).
src/mappings/helpers.ts:
Update the factory address on line 11.
Finally, we'll run the create and deploy commands. In order to avoid compatibility issues, let's use the graph-cli installed in the project (instead of the global version) by prefixing the graph
command with ./node_modules/.bin/
.
Well done, your subgraph is deployed! Now you can integrate the HTTP query URL printed by the deploy command into your website and use it to query data.
Authorization
To prevent your subgraph from being overwritten by others, please contact us on discord for an authorization key. If you are testing against the TestNet Graph, here is an access token for general testing purpose: a9a79c2aea604bfaa861ff93d46d0d11.
Last updated