-
Notifications
You must be signed in to change notification settings - Fork 155
Quick start edits #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick start edits #743
Changes from 4 commits
2c74b09
16618c1
2e4a95a
97499c9
b8470ca
02c3f9c
8b9cb84
b717de4
99e197b
6e34ec4
2c94b34
70de00b
67f434c
e63ce82
2398272
93c0d7f
9483cf3
c829a34
38e91cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,20 @@ | |
title: Quick Start | ||
--- | ||
|
||
This guide will quickly take you through how to initialize, create, and deploy your subgraph to Subgraph Studio. | ||
This guide walks you through the basics of creating, deploying, publishing, and querying a subgraph on The Graph easily. | ||
|
||
|
||
Ensure that your subgraph will be indexing data from a [supported network](/developing/supported-networks). | ||
|
||
This guide is written assuming that you have: | ||
**Prerequisites for this guide:** | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- A crypto wallet | ||
- A smart contract address on the network of your choice | ||
- A subgraph that will be indexing data from a [supported network](/developing/supported-networks/) | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- An API key | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## 1. Create a subgraph on Subgraph Studio | ||
|
||
Go to the [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet. | ||
## Step-by-Step | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Once your wallet is connected, you can begin by clicking “Create a Subgraph." It is recommended to name the subgraph in Title Case: "Subgraph Name Chain Name." | ||
### 1. Install the Graph CLI | ||
|
||
## 2. Install the Graph CLI | ||
|
||
The Graph CLI is written in TypeScript and you will need to have `node` and either `npm` or `yarn` installed to use it. Check that you have the most recent CLI version installed. | ||
The Graph CLI is written in TypeScript, and you must have `node` and either `npm` or `yarn` installed to use it. Check for the most recent CLI version. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
On your local machine, run one of the following commands: | ||
|
||
|
@@ -35,133 +31,141 @@ Using [yarn](https://yarnpkg.com/): | |
yarn global add @graphprotocol/graph-cli | ||
idalithb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
## 3. Initialize your subgraph from existing contract | ||
### 2. Create your subgraph | ||
idalithb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
If your contract has events, the `init` command will automatically create a scaffold of a subgraph. | ||
|
||
#### Create via CLI | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Use the following command to create a subgraph in Subgraph Studio using CLI: `init --product subgraph-studio` | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#### **Create via Subgraph Studio** | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Subgraph Studio is a review and staging environment where you can create, manage, deploy, and publish subgraphs and API Keys. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Initialize your subgraph from an existing contract by running the initialize command: | ||
1. Go to the [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
2. Click “Create a Subgraph." It is recommended to name the subgraph in Title Case: "Subgraph Name Chain Name." | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
For additional information on subgraph creation and CLI, see [Creating a Subgraph](developing/creating-a-subgraph). | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### 3. Initialize Your Subgraph | ||
|
||
#### **From an existing contract** | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
The following command initializes your subgraph from an existing contract: | ||
|
||
```sh | ||
graph init --studio <SUBGRAPH_SLUG> | ||
``` | ||
|
||
> You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/). | ||
> _Note: If your contract was verified on Etherscan, then the ABI will automatically be created in the CLI._ | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/). | ||
|
||
When you initialize your subgraph, the CLI tool will ask you for the following information: | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
- Protocol: choose the protocol your subgraph will be indexing data from | ||
- Subgraph slug: create a name for your subgraph. Your subgraph slug is an identifier for your subgraph. | ||
- Directory to create the subgraph in: choose your local directory | ||
- Ethereum network(optional): you may need to specify which EVM-compatible network your subgraph will be indexing data from | ||
- Protocol: Choose the protocol your subgraph will be indexing data from | ||
- Subgraph slug: Create a name for your subgraph. Your subgraph slug is an identifier for your subgraph. | ||
- Directory to create the subgraph in: Choose your local directory | ||
- Ethereum network(optional): You may need to specify which EVM-compatible network your subgraph will be indexing data from | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- Contract address: Locate the smart contract address you’d like to query data from | ||
- ABI: If the ABI is not autopopulated, you will need to input it manually as a JSON file | ||
- Start Block: it is suggested that you input the start block to save time while your subgraph indexes blockchain data. You can locate the start block by finding the block where your contract was deployed. | ||
- Contract Name: input the name of your contract | ||
- Index contract events as entities: it is suggested that you set this to true as it will automatically add mappings to your subgraph for every emitted event | ||
- Add another contract(optional): you can add another contract | ||
- ABI: If the ABI is not auto-populated, you will need to input it manually as a JSON file | ||
- Start Block: You should input the start block to optimize subgraph indexing of blockchain data. Locate the start block by finding the block where your contract was deployed. | ||
- Contract Name: Input the name of your contract | ||
- Index contract events as entities: It is suggested that you set this to true, as it will automatically add mappings to your subgraph for every emitted event | ||
- Add another contract(optional): You can add another contract. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
See the following screenshot for an example for what to expect when initializing your subgraph: | ||
|
||
 | ||
|
||
## 4. Write your subgraph | ||
### 4. Write your subgraph | ||
idalithb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The previous commands create a scaffold subgraph that you can use as a starting point for building your subgraph. When making changes to the subgraph, you will mainly work with three files: | ||
The `init` command in the previous step creates a scaffold subgraph that you can use as a starting point to build your subgraph. | ||
|
||
- Manifest (`subgraph.yaml`) - The manifest defines what datasources your subgraphs will index. | ||
- Schema (`schema.graphql`) - The GraphQL schema defines what data you wish to retrieve from the subgraph. | ||
- AssemblyScript Mappings (`mapping.ts`) - This is the code that translates data from your datasources to the entities defined in the schema. | ||
When making changes to the subgraph, you will mainly work with three files: | ||
|
||
For more information on how to write your subgraph, see [Creating a Subgraph](/developing/creating-a-subgraph). | ||
- Manifest (`subgraph.yaml`)- defines what datasources your subgraphs will index. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- Schema (`schema. graphql`) - defines what data you wish to retrieve from the subgraph. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- AssemblyScript Mappings (`mapping.ts`) - translates data from your datasources to the entities defined in the schema. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## 5. Deploy to Subgraph Studio | ||
For a detailed breakdown on how to write your subgraph, check out [Creating a Subgraph](/developing/creating-a-subgraph/). | ||
|
||
Once your subgraph is written, run the following commands: | ||
### 5. Deploy to your subgraph | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```sh | ||
$ graph codegen | ||
$ graph build | ||
``` | ||
Remember, deploying is not the same as publishing. | ||
|
||
- Authenticate and deploy your subgraph. The deploy key can be found on the Subgraph page in Subgraph Studio. | ||
- When you deploy a subgraph, you push it to [Subgraph Studio](https://thegraph.com/studio/), where you can test, stage and review it. | ||
- When you publish a subgraph, you are publishing it onchain to the decentralized network. | ||
|
||
```sh | ||
$ graph auth --studio <DEPLOY_KEY> | ||
$ graph deploy --studio <SUBGRAPH_SLUG> | ||
``` | ||
1. Once your subgraph is written, run the following commands: | ||
|
||
```sh | ||
$ graph codegen | ||
$ graph build | ||
``` | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
2. Authenticate and deploy your subgraph. The deploy key can be found on the Subgraph page in Subgraph Studio. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
You will be asked for a version label. It's strongly recommended to use [semver](https://semver.org/) for versioning like `0.0.1`. That said, you are free to choose any string as version such as:`v1`, `version1`, `asdf`. | ||
```sh | ||
$ graph auth --studio <DEPLOY_KEY> | ||
$ graph deploy --studio <SUBGRAPH_SLUG> | ||
``` | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## 6. Test your subgraph | ||
- The CLI will ask for a version label. | ||
- It's strongly recommended to use [semver](https://semver.org/) for versioning like `0.0.1.` That said, you can choose any string as version such as: `v1, version1, asdf`. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
In Subgraph Studio's playground environment, you can test your subgraph by making a sample query. | ||
### 6. Review your subgraph | ||
idalithb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The logs will tell you if there are any errors with your subgraph. The logs of an operational subgraph will look like this: | ||
If you’d like to examine your subgraph before publishing it to the network, you can use [Subgraph Studio](https://thegraph.com/studio/) to do the following: | ||
|
||
- Run a sample query. | ||
- Analyze your subgraph in the dashboard to check information. | ||
- Check the logs on the dashboard to see if there are any errors with your subgraph. | ||
- The logs of an operational subgraph will look like this: | ||
|
||
 | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
If your subgraph is failing, you can query the subgraph health by using the GraphiQL Playground. Note that you can leverage the query below and input your deployment ID for your subgraph. In this case, `Qm...` is the deployment ID (which can be located on the Subgraph page under **Details**). The query below will tell you when a subgraph fails, so you can debug accordingly: | ||
|
||
```graphql | ||
{ | ||
indexingStatuses(subgraphs: ["Qm..."]) { | ||
node | ||
synced | ||
health | ||
fatalError { | ||
message | ||
block { | ||
number | ||
hash | ||
} | ||
handler | ||
} | ||
nonFatalErrors { | ||
message | ||
block { | ||
number | ||
hash | ||
} | ||
handler | ||
} | ||
chains { | ||
network | ||
chainHeadBlock { | ||
number | ||
} | ||
earliestBlock { | ||
number | ||
} | ||
latestBlock { | ||
number | ||
} | ||
lastHealthyBlock { | ||
number | ||
} | ||
} | ||
entityCount | ||
} | ||
} | ||
``` | ||
### 7. Publish Your Subgraph to The Graph | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## 7. Publish your subgraph to The Graph’s Decentralized Network | ||
Publishing a subgraph to the decentralized network makes it available for [Curators](/network/curating/) to begin curating it and [Indexers](/network/indexing/) to index it. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Once your subgraph has been deployed to Subgraph Studio, you have tested it out, and you are ready to put it into production, you can then publish it to the decentralized network. | ||
#### Publishing with Subgraph Studio | ||
|
||
In Subgraph Studio, you will be able to click the publish button on the top right of your subgraph's page. | ||
1. To publish your subgraph, click the publish button in the dashboard. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
2. Select the network to which you would like to publish your subgraph. | ||
- Subgraphs are published to Arbitrum One to take advantage of the [faster transaction speeds and lower gas costs](https://thegraph.com/docs/en/arbitrum/arbitrum-faq/). | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Select the network you would like to publish your subgraph to. It is recommended to publish subgraphs to Arbitrum One to take advantage of the [faster transaction speeds and lower gas costs](/arbitrum/arbitrum-faq). | ||
#### Publishing from the CLI | ||
benface marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The (upgrade Indexer)[/sunrise/#about-the-upgrade-indexer] will begin serving queries on your subgraph regardless of subgraph curation, and it will provide you with 100,000 free queries per month. | ||
As of version 0.73.0, you can also publish your subgraph with the [`graph-cli`](https://github.com/graphprotocol/graph-tooling/tree/main/packages/cli). | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
For a higher quality of service and stronger redundancy, you can curate your subgraph to attract more Indexers. At the time of writing, it is recommended that you curate your own subgraph with at least 3,000 GRT to ensure 3-5 additional Indexers begin serving queries on your subgraph. | ||
1. Open the `graph-cli`. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
2. Use the following commands: `graph codegen && graph build` then `graph publish`. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
3. A window will open, allowing you to connect your wallet, add metadata, and deploy your finalized subgraph to a network of your choice. | ||
|
||
To save on gas costs, you can curate your subgraph in the same transaction that you published it by selecting this button when you publish your subgraph to The Graph’s decentralized network: | ||
 | ||
|
||
 | ||
To customize your deployment see [publishing a subgraph](/publishing/publishing-a-subgraph/) | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#### Adding signal to your subgraph | ||
|
||
## 8. Query your subgraph | ||
1. To attract indexers to query your subgraph, you should add GRT curation signal to it. | ||
|
||
- This action improves quality of service, reduces latency, and enhances network redundancy and availability for your subgraphs. | ||
|
||
2. If eligible for indexing rewards, Indexers receive GRT rewards based on the signaled amount. | ||
|
||
- It’s recommended to curate at least 3,000 GRT to attract 3 Indexers. Check reward eligibility based on subgraph feature usage and supported networks. | ||
|
||
To learn more about curation, read [Curating](/network/curating/). | ||
|
||
To save on gas costs, you can curate your subgraph in the same transaction you publish it by selecting this button: | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
 | ||
|
||
Now, you can query your subgraph by sending GraphQL queries to your subgraph’s Query URL, which you can find by clicking on the query button. | ||
### 8. Query Your Subgraph | ||
|
||
If you don't have your API key, you can query via the free, rate-limited development query URL, which can be used for development and staging. | ||
Now, you can query your subgraph by sending GraphQL queries to your subgraph’s Query URL, which you can find by clicking the query button. | ||
idalithb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
For more information about querying data from your subgraph, read more [here](/querying/querying-the-graph/). | ||
For more information about querying data from your subgraph, read [Querying The Graph](/querying/querying-the-graph/). |
Uh oh!
There was an error while loading. Please reload this page.