Skip to content

Commit 52cecae

Browse files
committed
revisions
1 parent eed83ff commit 52cecae

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

website/pages/en/developing/creating-a-subgraph.mdx

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
title: Creating a Subgraph
33
---
44

5-
This comprehensive guide provides detailed instructions to create a subgraph successfully.
5+
This detailed guide provides instructions to successfully create a subgraph.
66

77
A subgraph extracts data from a blockchain, processes it, and stores it for efficient querying via GraphQL.
88

9-
Before you begin, ensure you [create an API Key](deploying/subgraph-studio-faqs/#2-how-do-i-create-an-api-key) to enable your subgraph on The Graph.
10-
119
![Defining a Subgraph](/img/defining-a-subgraph.png)
1210

11+
> In order to use your subgraph on The Graph's decentralized network, you will need to [create an API key](/deploying/subgraph-studio-faqs/#2-how-do-i-create-an-api-key) in [Subgraph Studio](https://thegraph.com/studio/apikeys/). It is recommended that you add signal to your subgraph with at least 3,000 GRT.
12+
1313
## Getting Started
1414

1515
### Install the Graph CLI
@@ -53,27 +53,29 @@ graph init \
5353
<SUBGRAPH_SLUG> [<DIRECTORY>]
5454
```
5555

56-
- The graph-cli relies on a public RPC endpoint, which is rate-limited. While occasional failures are expected, retries typically resolve the issue. If failures persist, consider using a local ABI.
56+
- The command tries to retrieve the contract ABI from Etherscan.
57+
58+
- The `graph-cli` relies on a public RPC endpoint. While occasional failures are expected, retries typically resolve this issue. If failures persist, consider using a local ABI.
5759

5860
- If any of the optional arguments are missing, it guides you through an interactive form.
5961

60-
- The `<SUBGRAPH_SLUG>` is the ID of your subgraph in Subgraph Studio. It can be found on your subgraph details page.
62+
- The `<SUBGRAPH_SLUG>` is the ID of your subgraph in [Subgraph Studio](https://thegraph.com/studio/). It can be found on your subgraph details page.
6163

62-
### From a demo subgraph
64+
### From an example subgraph
6365

6466
The following command creates a new project from an example subgraph:
6567

6668
```sh
6769
graph init --studio <SUBGRAPH_SLUG>
6870
```
6971

70-
- The example subgraph is based on the Gravity contract by Dani Grant, which manages user avatars and emits `NewGravatar` or `UpdateGravatar` events whenever avatars are created or updated.
72+
- The [example subgraph](https://github.com/graphprotocol/example-subgraph) is based on the Gravity contract by Dani Grant, which manages user avatars and emits `NewGravatar` or `UpdateGravatar` events whenever avatars are created or updated.
7173

7274
- The subgraph handles these events by writing `Gravatar` entities to the Graph Node store and ensuring these are updated according to the events
7375

7476
### Add new dataSources to an existing subgraph
7577

76-
Since v0.31.0, the `graph-cli` supports adding new dataSources to an existing subgraph through the `graph add` command:
78+
Since `v0.31.0`, the `graph-cli` supports adding new dataSources to an existing subgraph through the `graph add` command:
7779

7880
```sh
7981
graph add <address> [<subgraph-manifest default: "./subgraph.yaml">]
@@ -86,11 +88,9 @@ Options:
8688
--network-file <path> Networks config file path (default: "./networks.json")
8789
```
8890

89-
**Specifics**
91+
#### Specifics
9092

91-
The `add` command will fetch the ABI from Etherscan unless an ABI path is specified with the `--abi` option. Subsequently, it will create a new `dataSource` like `graph init` command creates a dataSource `--from-contract` and will update the schema and mappings accordingly.
92-
93-
> Note: This allows you to index implementation contracts from their proxy contracts.
93+
The `add` command will fetch the ABI from Etherscan unless an ABI path is specified with the `--abi` option. Subsequently, it will create a new `dataSource` like `graph init` command creates a dataSource `--from-contract` and will update the schema and mappings accordingly. This allows you to index implementation contracts from their proxy contracts.
9494

9595
- The `--merge-entities` option identifies how the developer would like to handle `entity` and `event` name conflicts:
9696

@@ -106,39 +106,25 @@ The `add` command will fetch the ABI from Etherscan unless an ABI path is specif
106106

107107
### The Subgraph Manifest
108108

109-
The subgraph manifest, `subgraph.yaml`, specifies the following:
110-
111-
- The smart contracts to index
112-
113-
- The events from these contracts
109+
The subgraph manifest, `subgraph.yaml`, defines the smart contracts your subgraph will index, the events from these contracts to pay attention to, and how to map event data to entities that Graph Node stores and allows to query.
114110

115-
- The mapping of event data that Graph Node stores and queries
116-
117-
The subgraph definition consists of the following files:
111+
The **subgraph definition** consists of the following files:
118112

119113
- `subgraph.yaml`: Contains the subgraph manifest
120114

121115
- `schema.graphql`: a GraphQL schema defining the data stored for your subgraph and how to query it via GraphQL.
122116

123-
- `AssemblyScript` Mappings: [Assembly Script](https://github.com/AssemblyScript/assemblyscript) code that translates event data into entities defined in your schema (e.g. mapping.ts in this guide)
117+
- `mapping.ts`: [AssemblyScript Mappings](https://github.com/AssemblyScript/assemblyscript) code that translates event data into entities defined in your schema (e.g. `mapping.ts` in this guide)
124118

125119
A single subgraph can:
126120

127-
- Index data from multiple smart contracts
121+
- Index data from multiple smart contracts (but not multiple networks)
128122

129123
- Add an entry for each contract that requires indexing to the `dataSources array`.
130124

131-
The subgraph definition consists of a few files:
132-
133-
- `subgraph.yaml`: a YAML file containing the subgraph manifest
134-
135-
- `schema.graphql`: a GraphQL schema that defines what data is stored for your subgraph, and how to query it via GraphQL
136-
137-
- `AssemblyScript Mappings`: [AssemblyScript](https://github.com/AssemblyScript/assemblyscript) code that translates from the event data to the entities defined in your schema (e.g. `mapping.ts` in this tutorial)
138-
139125
The full specification for subgraph manifests can be found [here](https://github.com/graphprotocol/graph-node/blob/master/docs/subgraph-manifest.md).
140126

141-
For the demo subgraph listed above, `subgraph.yaml` is:
127+
For the example subgraph listed above, `subgraph.yaml` is:
142128

143129
```yaml
144130
specVersion: 0.0.4
@@ -392,7 +378,7 @@ calls:
392378
Details for the example above:
393379

394380
- ` global0X128` is the declared `eth_call`.
395-
- The text before colon(`global0X128`) is the label for this `eth_call` which is used when logging errors.
381+
- The text (`global0X128`) is the label for this `eth_call` which is used when logging errors.
396382
- The text (`Pool[event.address].feeGrowthGlobal0X128()`) is the actual `eth_call` that will be executed, which is in the form of `Contract[address].function(arguments)`
397383
- The `address` and `arguments` can be replaced with variables that will be available when the handler is executed.
398384

0 commit comments

Comments
 (0)