Skip to content

Commit aa721d8

Browse files
idalithbMichaelMacaulaybenface
authored
Quick start edits (#743)
* removing outdated info * copy edits * adding screenshot * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update quick-start.mdx * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/quick-start.mdx Co-authored-by: Benoît Rouleau <[email protected]> --------- Co-authored-by: Michael Macaulay <[email protected]> Co-authored-by: Benoît Rouleau <[email protected]>
1 parent d24d667 commit aa721d8

File tree

2 files changed

+127
-108
lines changed

2 files changed

+127
-108
lines changed

website/pages/en/quick-start.mdx

Lines changed: 127 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22
title: Quick Start
33
---
44

5-
This guide will quickly take you through how to initialize, create, and deploy your subgraph to Subgraph Studio.
5+
Learn how to easily publish and query a [subgraph](/developing/developer-faqs/#1-what-is-a-subgraph) on The Graph.
66

7-
Ensure that your subgraph will be indexing data from a [supported network](/developing/supported-networks).
8-
9-
This guide is written assuming that you have:
7+
## Prerequisites for this guide
108

119
- A crypto wallet
12-
- A smart contract address on the network of your choice
13-
14-
## 1. Create a subgraph on Subgraph Studio
15-
16-
Go to the [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet.
10+
- A smart contract address on one of the [supported networks](/developing/supported-networks/)
1711

18-
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."
12+
## Step-by-step
1913

20-
## 2. Install the Graph CLI
14+
### 1. Install the Graph CLI
2115

22-
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.
16+
You must have [Node.js](https://nodejs.org/) and a package manager of your choice (`npm`, `yarn` or `pnpm`) installed to use the Graph CLI. Check for the [most recent](https://github.com/graphprotocol/graph-tooling/releases?q=%40graphprotocol%2Fgraph-cli&expanded=true) CLI version.
2317

2418
On your local machine, run one of the following commands:
2519

@@ -35,133 +29,158 @@ Using [yarn](https://yarnpkg.com/):
3529
yarn global add @graphprotocol/graph-cli
3630
```
3731

38-
## 3. Initialize your subgraph from an existing contract
32+
### 2. Create your subgraph
3933

40-
Initialize your subgraph from an existing contract by running the initialize command:
34+
If your contract has events, the `init` command will automatically create a scaffold of a subgraph.
35+
36+
#### Create via Graph CLI
37+
38+
Use the following command to create a subgraph in Subgraph Studio using the CLI:
39+
40+
```sh
41+
graph init --product subgraph-studio
42+
```
43+
44+
#### Create via Subgraph Studio
45+
46+
Subgraph Studio lets you create, manage, deploy, and publish subgraphs, as well as create and manage API keys.
47+
48+
1. Go to [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet.
49+
2. Click "Create a Subgraph". It is recommended to name the subgraph in Title Case: "Subgraph Name Chain Name".
50+
51+
For additional information on subgraph creation and the Graph CLI, see [Creating a Subgraph](/developing/creating-a-subgraph).
52+
53+
### 3. Initialize your subgraph
54+
55+
#### From an existing contract
56+
57+
The following command initializes your subgraph from an existing contract:
4158

4259
```sh
4360
graph init --studio <SUBGRAPH_SLUG>
4461
```
4562

46-
> You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
63+
> Note: If your contract was verified on Etherscan, then the ABI will automatically be created in the CLI.
4764
48-
When you initialize your subgraph, the CLI tool will ask you for the following information:
65+
You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
4966

50-
- Protocol: choose the protocol your subgraph will be indexing data from
51-
- Subgraph slug: create a name for your subgraph. Your subgraph slug is an identifier for your subgraph.
52-
- Directory to create the subgraph in: choose your local directory
53-
- Ethereum network(optional): you may need to specify which EVM-compatible network your subgraph will be indexing data from
54-
- Contract address: Locate the smart contract address you’d like to query data from
55-
- ABI: If the ABI is not autopopulated, you will need to input it manually as a JSON file
56-
- 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.
57-
- Contract Name: input the name of your contract
58-
- 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
59-
- Add another contract(optional): you can add another contract
67+
When you initialize your subgraph, the CLI will ask you for the following information:
68+
69+
- Protocol: Choose the protocol your subgraph will be indexing data from.
70+
- Subgraph slug: Create a name for your subgraph. Your subgraph slug is an identifier for your subgraph.
71+
- Directory to create the subgraph in: Choose your local directory.
72+
- Ethereum network (optional): You may need to specify which EVM-compatible network your subgraph will be indexing data from.
73+
- Contract address: Locate the smart contract address you’d like to query data from.
74+
- ABI: If the ABI is not auto-populated, you will need to input it manually as a JSON file.
75+
- 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.
76+
- Contract Name: Input the name of your contract.
77+
- 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.
78+
- Add another contract (optional): You can add another contract.
6079

6180
See the following screenshot for an example for what to expect when initializing your subgraph:
6281

6382
![Subgraph command](/img/subgraph-init-example.png)
6483

65-
## 4. Write your subgraph
84+
### 4. Write your subgraph
6685

67-
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:
86+
The `init` command in the previous step creates a scaffold subgraph that you can use as a starting point to build your subgraph.
6887

69-
- Manifest (`subgraph.yaml`) - The manifest defines what datasources your subgraphs will index.
70-
- Schema (`schema.graphql`) - The GraphQL schema defines what data you wish to retrieve from the subgraph.
71-
- AssemblyScript Mappings (`mapping.ts`) - This is the code that translates data from your datasources to the entities defined in the schema.
88+
When making changes to the subgraph, you will mainly work with three files:
7289

73-
For more information on how to write your subgraph, see [Creating a Subgraph](/developing/creating-a-subgraph).
90+
- Manifest (`subgraph.yaml`) - defines what data sources your subgraph will index.
91+
- Schema (`schema.graphql`) - defines what data you wish to retrieve from the subgraph.
92+
- AssemblyScript Mappings (`mapping.ts`) - translates data from your data sources to the entities defined in the schema.
7493

75-
## 5. Deploy to Subgraph Studio
94+
For a detailed breakdown on how to write your subgraph, check out [Creating a Subgraph](/developing/creating-a-subgraph/).
7695

77-
Once your subgraph is written, run the following commands:
96+
### 5. Deploy your subgraph
7897

79-
```sh
80-
$ graph codegen
81-
$ graph build
82-
```
98+
Remember, deploying is not the same as publishing.
8399

84-
- Authenticate and deploy your subgraph. The deploy key can be found on the Subgraph page in Subgraph Studio.
100+
- When you deploy a subgraph, you push it to [Subgraph Studio](https://thegraph.com/studio/), where you can test, stage and review it.
101+
- When you publish a subgraph, you are publishing it onchain to the decentralized network.
85102

86-
```sh
87-
$ graph auth --studio <DEPLOY_KEY>
88-
$ graph deploy --studio <SUBGRAPH_SLUG>
89-
```
103+
1. Once your subgraph is written, run the following commands:
90104

91-
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`.
92-
93-
## 6. Test your subgraph
94-
95-
In Subgraph Studio's playground environment, you can test your subgraph by making a sample query.
96-
97-
The logs will tell you if there are any errors with your subgraph. The logs of an operational subgraph will look like this:
98-
99-
![Subgraph logs](/img/subgraph-logs-image.png)
100-
101-
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:
102-
103-
```graphql
104-
{
105-
indexingStatuses(subgraphs: ["Qm..."]) {
106-
node
107-
synced
108-
health
109-
fatalError {
110-
message
111-
block {
112-
number
113-
hash
114-
}
115-
handler
116-
}
117-
nonFatalErrors {
118-
message
119-
block {
120-
number
121-
hash
122-
}
123-
handler
124-
}
125-
chains {
126-
network
127-
chainHeadBlock {
128-
number
129-
}
130-
earliestBlock {
131-
number
132-
}
133-
latestBlock {
134-
number
135-
}
136-
lastHealthyBlock {
137-
number
138-
}
139-
}
140-
entityCount
141-
}
142-
}
143-
```
105+
```sh
106+
graph codegen
107+
graph build
108+
```
144109

145-
## 7. Publish your subgraph to The Graph’s Decentralized Network
110+
2. Authenticate and deploy your subgraph. The deploy key can be found on the subgraph's page in Subgraph Studio.
146111

147-
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.
112+
![Deploy key](/img/subgraph-studio-deploy-key.jpg)
148113

149-
In Subgraph Studio, you will be able to click the publish button on the top right of your subgraph's page.
114+
```sh
150115

151-
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).
116+
graph auth --studio <DEPLOY_KEY>
152117

153-
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.
118+
graph deploy --studio <SUBGRAPH_SLUG>
119+
```
154120

155-
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.
121+
- The CLI will ask for a version label.
122+
- It's strongly recommended to use [semantic versioning](https://semver.org/), e.g. `0.0.1`. That said, you can choose any string for the version such as: `v1`, `version1`, `asdf`, etc.
156123

157-
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:
124+
### 6. Review your subgraph
158125

159-
![Subgraph publish](/img/publish-and-signal-tx.png)
126+
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:
127+
128+
- Run a sample query.
129+
- Analyze your subgraph in the dashboard to check information.
130+
- 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:
160131

161-
## 8. Query your subgraph
132+
![Subgraph logs](/img/subgraph-logs-image.png)
133+
134+
### 7. Publish your subgraph to The Graph Network
135+
136+
Publishing a subgraph to the decentralized network makes it available for [Curators](/network/curating/) to begin curating it and [Indexers](/network/indexing/) to begin indexing it.
137+
138+
#### Publishing with Subgraph Studio
139+
140+
1. To publish your subgraph, click the Publish button in the dashboard.
141+
2. Select the network to which you would like to publish your subgraph.
142+
143+
#### Publishing from the CLI
144+
145+
As of version 0.73.0, you can also publish your subgraph with the Graph CLI.
146+
147+
1. Open the `graph-cli`.
148+
2. Use the following commands:
149+
150+
```sh
151+
graph codegen && graph build
152+
```
153+
154+
Then,
155+
156+
```sh
157+
graph publish
158+
```
159+
160+
3. A window will open, allowing you to connect your wallet, add metadata, and deploy your finalized subgraph to a network of your choice.
161+
162+
![cli-ui](/img/cli-ui.png)
163+
164+
To customize your deployment, see [Publishing a Subgraph](/publishing/publishing-a-subgraph/).
165+
166+
#### Adding signal to your subgraph
167+
168+
1. To attract indexers to query your subgraph, you should add GRT curation signal to it.
169+
170+
- This action improves quality of service, reduces latency, and enhances network redundancy and availability for your subgraph.
171+
172+
2. If eligible for indexing rewards, Indexers receive GRT rewards based on the signaled amount.
173+
174+
- 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.
175+
176+
To learn more about curation, read [Curating](/network/curating/).
177+
178+
To save on gas costs, you can curate your subgraph in the same transaction you publish it by selecting this option:
179+
180+
![Subgraph publish](/img/publish-and-signal-tx.png)
162181

163-
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.
182+
### 8. Query your subgraph
164183

165-
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.
184+
Now, you can query your subgraph by sending GraphQL queries to its Query URL, which you can find by clicking the Query button.
166185

167-
For more information about querying data from your subgraph, read more [here](/querying/querying-the-graph/).
186+
For more information about querying data from your subgraph, read [Querying The Graph](/querying/querying-the-graph/).
548 KB
Loading

0 commit comments

Comments
 (0)