You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
24
38
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:
26
53
27
54
```sh
28
55
graph init --studio <SUBGRAPH_SLUG>
29
56
```
30
57
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
-

58
+
See the following screenshot for an example for what to expect when initializing your subgraph:
34
59
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.
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:
40
65
@@ -44,11 +69,9 @@ The previous commands create a scaffold subgraph that you can use as a starting
44
69
45
70
For more information on how to write your subgraph, see [Creating a Subgraph](/developing/creating-a-subgraph).
46
71
47
-
### 4. Deploy to the Subgraph Studio
72
+
### 5. Deploy to the Subgraph Studio
48
73
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:
- 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.
66
93
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:
68
95
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
+

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:
70
99
71
100
```sh
72
101
{
@@ -110,119 +139,26 @@ The logs should tell you if there are any errors. If your subgraph is failing, y
110
139
}
111
140
```
112
141
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
118
143
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.
120
145
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.
130
147
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).
132
149
133
-
- Initialize your subgraph from an existing contract.
- 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.
172
151
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.
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:
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
183
159
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.
225
161
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.
227
163
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/).
0 commit comments