|
2 | 2 | title: Creating a Subgraph
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -Before being able to use the Graph CLI, you need to create your subgraph in [Subgraph Studio](https://thegraph.com/studio). You will then be able to setup your subgraph project and deploy it to the platform of your choice. Note that **subgraphs that do not index Ethereum mainnet will not be published to The Graph Network**. |
| 5 | +A subgraph extracts data from a blockchain, processing it and storing it so that it can be easily queried via GraphQL. |
6 | 6 |
|
7 |
| -The `graph init` command can be used to set up a new subgraph project, either from an existing contract on any of the public Ethereum networks or from an example subgraph. This command can be used to create a subgraph on the Subgraph Studio by passing in `graph init --product subgraph-studio`. If you already have a smart contract deployed to Ethereum mainnet or one of the testnets, bootstrapping a new subgraph from that contract can be a good way to get started. |
| 7 | + |
| 8 | + |
| 9 | +The subgraph definition consists of a few files: |
| 10 | + |
| 11 | +- `subgraph.yaml`: a YAML file containing the subgraph manifest |
| 12 | + |
| 13 | +- `schema.graphql`: a GraphQL schema that defines what data is stored for your subgraph, and how to query it via GraphQL |
| 14 | + |
| 15 | +- `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) |
| 16 | + |
| 17 | +Before you go into detail about the contents of the manifest file, you need to install the [Graph CLI](https://github.com/graphprotocol/graph-cli) which you will need to build and deploy a subgraph. |
| 18 | + |
| 19 | +## Install the Graph CLI |
| 20 | + |
| 21 | +The Graph CLI is written in JavaScript, and you will need to install either `yarn` or `npm` to use it; it is assumed that you have yarn in what follows. |
| 22 | + |
| 23 | +Once you have `yarn`, install the Graph CLI by running |
| 24 | + |
| 25 | +**Install with yarn:** |
| 26 | + |
| 27 | +```bash |
| 28 | +yarn global add @graphprotocol/graph-cli |
| 29 | +``` |
| 30 | + |
| 31 | +**Install with npm:** |
| 32 | + |
| 33 | +```bash |
| 34 | +npm install -g @graphprotocol/graph-cli |
| 35 | +``` |
| 36 | + |
| 37 | +Once installed, the `graph init` command can be used to set up a new subgraph project, either from an existing contract on any of the public Ethereum networks or from an example subgraph. This command can be used to create a subgraph on the Subgraph Studio by passing in `graph init --product subgraph-studio`. If you already have a smart contract deployed to Ethereum mainnet or one of the testnets, bootstrapping a new subgraph from that contract can be a good way to get started. |
8 | 38 |
|
9 | 39 | ## From An Existing Contract
|
10 | 40 |
|
|
0 commit comments