Skip to content

Commit 29d307d

Browse files
Updating quickstart (#323)
1 parent 6b7da2b commit 29d307d

File tree

4 files changed

+57
-121
lines changed

4 files changed

+57
-121
lines changed

website/pages/en/cookbook/quick-start.mdx

Lines changed: 57 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ This guide will quickly take you through how to initialize, create, and deploy y
66

77
Ensure that your subgraph will be indexing data from a [supported network](/developing/supported-networks).
88

9-
## Subgraph Studio
9+
This guide is written assuming that you have:
1010

11-
### 1. Install the Graph CLI
11+
- A smart contract address on the network of your choice
12+
- GRT to curate your subgraph
13+
- A crypto wallet
14+
15+
### 1. Create a subgraph on Subgraph Studio
16+
17+
Go to the Subgraph Studio [https://thegraph.com/studio/](https://thegraph.com/studio/) and connect your wallet.
18+
19+
Once connected, you can begin by clicking “create a subgraph.” Select the network of your choice and click continue.
20+
21+
### 2. Install the Graph CLI
1222

1323
The Graph CLI is written in JavaScript and you will need to have either `npm` or `yarn` installed to use it.
1424

25+
On your local machine, run one of the following commands:
26+
1527
```sh
1628
# NPM
1729
$ npm install -g @graphprotocol/graph-cli
@@ -20,21 +32,34 @@ $ npm install -g @graphprotocol/graph-cli
2032
$ yarn global add @graphprotocol/graph-cli
2133
```
2234

23-
### 2. Initialize your Subgraph
35+
### 3. Initialize your Subgraph
36+
37+
> You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
2438
25-
- Initialize your subgraph from an existing contract.
39+
When you initialize your subgraph, the CLI tool will ask you for the following information:
40+
41+
- Protocol: choose the protocol your subgraph will be indexing data from
42+
- Subgraph slug: create a name for your subgraph. Your subgraph slug is an identifier for your subgraph.
43+
- Directory to create the subgraph in: choose your local directory
44+
- Ethereum network(optional): you may need to specify which EVM-compatible network your subgraph will be indexing data from
45+
- Contract address: Locate the smart contract address you’d like to query data from
46+
- ABI: If the ABI is not autopopulated, you will need to input it manually as a JSON file
47+
- 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.
48+
- Contract Name: input the name of your contract
49+
- 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
50+
- Add another contract(optional): you can add another contract
51+
52+
Initialize your subgraph from an existing contract by running the following command:
2653

2754
```sh
2855
graph init --studio <SUBGRAPH_SLUG>
2956
```
3057

31-
- Your subgraph slug is an identifier for your subgraph. The CLI tool will walk you through the steps for creating a subgraph, such as contract address, network, etc as you can see in the screenshot below.
32-
33-
![Subgraph command](/img/Subgraph-Slug.png)
58+
See the following screenshot for an example for what to expect when initializing your subgraph:
3459

35-
> Note: Consider adding `--index-events` to the command above to save time. It bootstraps the subgraph with entities in the schema and simple mappings for each emitted event.
60+
![Subgraph command](/img/subgraph-init-example.png)
3661

37-
### 3. Write your Subgraph
62+
### 4. Write your Subgraph
3863

3964
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:
4065

@@ -44,11 +69,9 @@ The previous commands create a scaffold subgraph that you can use as a starting
4469

4570
For more information on how to write your subgraph, see [Creating a Subgraph](/developing/creating-a-subgraph).
4671

47-
### 4. Deploy to the Subgraph Studio
72+
### 5. Deploy to the Subgraph Studio
4873

49-
- Go to the Subgraph Studio [https://thegraph.com/studio/](https://thegraph.com/studio/) and connect your wallet.
50-
- Click "Create" and enter the subgraph slug you used in step 2.
51-
- Run these commands in the subgraph folder
74+
Once your subgraph is written, run the following commands:
5275

5376
```sh
5477
$ graph codegen
@@ -62,11 +85,17 @@ $ graph auth --studio <DEPLOY_KEY>
6285
$ graph deploy --studio <SUBGRAPH_SLUG>
6386
```
6487

65-
- You will be asked for a version label. It's strongly recommended to use the following conventions for naming your versions. Example: `0.0.1`, `v1`, `version1`
88+
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`.
89+
90+
### 6. Test your subgraph
91+
92+
You can test your subgraph by making a sample query in the playground section.
6693

67-
### 5. Check your logs
94+
The logs will tell you if there are any errors with your subgraph. The logs of an operational subgraph will look like this:
6895

69-
The logs should tell you if there are any errors. If your subgraph is failing, you can query the subgraph health by using the [GraphiQL Playground](https://graphiql-online.com/). Use [this endpoint](https://api.thegraph.com/index-node/graphql). 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:
96+
![Subgraph logs](/img/subgraph-logs-image.png)
97+
98+
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:
7099

71100
```sh
72101
{
@@ -110,119 +139,26 @@ The logs should tell you if there are any errors. If your subgraph is failing, y
110139
}
111140
```
112141

113-
### 6. Query your Subgraph
114-
115-
You can now query your subgraph by following [these instructions](/querying/querying-the-graph). You can query from your dApp if you don't have your API key via the free, rate-limited temporary query URL that can be used for development and staging. You can read the additional instructions for how to query a subgraph from a frontend application [here](/querying/querying-from-an-application).
116-
117-
## Hosted Service
142+
### 7. Publish Your Subgraph to The Graph’s Decentralized Network
118143

119-
### 1. Install the Graph CLI
144+
Once your subgraph has been deployed to the Subgraph Studio, you have tested it out, and are ready to put it into production, you can then publish it to the decentralized network.
120145

121-
"The Graph CLI is an npm package and you will need `npm` or `yarn` installed to use it.
122-
123-
```sh
124-
# NPM
125-
$ npm install -g @graphprotocol/graph-cli
126-
127-
# Yarn
128-
$ yarn global add @graphprotocol/graph-cli
129-
```
146+
In the Subgraph Studio, click on your subgraph. On the subgraph’s page, you will be able to click the publish button on the top right.
130147

131-
### 2. Initialize your Subgraph
148+
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-faq).
132149

133-
- Initialize your subgraph from an existing contract.
134-
135-
```sh
136-
$ graph init --product hosted-service --from-contract <Address>
137-
```
138-
139-
- You will be asked for a subgraph name. The format is `<Github>/<Subgraph Name>`. Ex: `graphprotocol/examplesubgraph`
140-
141-
- If you'd like to initialize from an example, run the command below:
142-
143-
```sh
144-
$ graph init --product hosted-service --from-example
145-
```
146-
147-
- In the case of the example, the subgraph is based on the Gravity contract by Dani Grant that manages user avatars and emits `NewGravatar` or `UpdateGravatar` events whenever avatars are created or updated.
148-
149-
### 3. Write your Subgraph
150-
151-
The previous command will have created a scaffold from where you can build your subgraph. When making changes to the subgraph, you will mainly work with three files:
152-
153-
- Manifest (subgraph.yaml) - The manifest defines what datasources your subgraph will index
154-
- Schema (schema.graphql) - The GraphQL schema define what data you wish to retrieve from the subgraph
155-
- AssemblyScript Mappings (mapping.ts) - This is the code that translates data from your datasources to the entities defined in the schema
156-
157-
For more information on how to write your subgraph, see [Creating a Subgraph](/developing/creating-a-subgraph).
158-
159-
### 4. Deploy your Subgraph
160-
161-
- Sign into the [Hosted Service](https://thegraph.com/hosted-service/) using your GitHub account
162-
- Click Add Subgraph and fill out the required information. Use the same subgraph name as in step 2.
163-
- Run `codegen` in the subgraph folder
164-
165-
```sh
166-
# NPM
167-
$ npm run codegen
168-
169-
# Yarn
170-
$ yarn codegen
171-
```
150+
Before you can query your subgraph, Indexers need to begin serving queries on it. In order to streamline this process, you can curate your own subgraph using GRT.
172151

173-
- Add your Access token and deploy your subgraph. The access token is found on your dashboard in the Hosted Service.
152+
At the time of writing, it is recommended that you curate your own subgraph with 10,000 GRT to ensure that it is indexed and available for querying as soon as possible.
174153

175-
```sh
176-
$ graph auth --product hosted-service <ACCESS_TOKEN>
177-
$ graph deploy --product hosted-service <GITHUB_USER>/<SUBGRAPH NAME>
178-
```
154+
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:
179155

180-
### 5. Check your logs
156+
![Subgraph publish](/img/publish-and-signal-tx.png)
181157

182-
The logs should tell you if there are any errors. If your subgraph is failing, you can query the subgraph health by using the [GraphiQL Playground](https://graphiql-online.com/). Use [this endpoint](https://api.thegraph.com/index-node/graphql). 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:
158+
### 8. Query your Subgraph
183159

184-
```sh
185-
{
186-
indexingStatuses(subgraphs: ["Qm..."]) {
187-
node
188-
synced
189-
health
190-
fatalError {
191-
message
192-
block {
193-
number
194-
hash
195-
}
196-
handler
197-
}
198-
nonFatalErrors {
199-
message
200-
block {
201-
number
202-
hash
203-
}
204-
handler
205-
}
206-
chains {
207-
network
208-
chainHeadBlock {
209-
number
210-
}
211-
earliestBlock {
212-
number
213-
}
214-
latestBlock {
215-
number
216-
}
217-
lastHealthyBlock {
218-
number
219-
}
220-
}
221-
entityCount
222-
}
223-
}
224-
```
160+
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.
225161

226-
### 6. Query your Subgraph
162+
You can query from your dapp if you don't have your API key via the free, rate-limited temporary query URL that can be used for development and staging.
227163

228-
Follow [these instructions](/querying/querying-the-hosted-service) to query your subgraph on the Hosted Service.
164+
For more information about querying data from your subgraph, read more [here](../querying/querying-the-graph/).
514 KB
Loading
425 KB
Loading
456 KB
Loading

0 commit comments

Comments
 (0)