Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing quick start #836

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion website/pages/en/network/benefits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ The Graph’s decentralized network gives users access to geographic redundancy

Bottom line: The Graph Network is less expensive, easier to use, and produces superior results compared to running a `graph-node` locally.

Start using The Graph Network today, and learn how to [upgrade your subgraph to The Graph's decentralized network](/cookbook/upgrading-a-subgraph).
Start using The Graph Network today, and learn how to [publish your subgraph to The Graph's decentralized network](/quick-start).
90 changes: 41 additions & 49 deletions website/pages/en/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
title: Quick Start
---

Learn how to easily publish and query a [subgraph](/developing/developer-faqs/#1-what-is-a-subgraph) on The Graph.
Learn how to easily build, publish and query a [subgraph](/developing/developer-faqs/#1-what-is-a-subgraph) on The Graph.

## Prerequisites for this guide
## Prerequisites

- A crypto wallet
- A smart contract address on one of the [supported networks](/developing/supported-networks/)
- A smart contract address on a [supported network](/developing/supported-networks/)
- [Node.js](https://nodejs.org/) installed
- A package manager of your choice (`npm`, `yarn` or `pnpm`)

## Step-by-step
## How to Build a Subgraph

### 1. Install the Graph CLI
### 1. Create a subgraph in Subgraph Studio

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.
Go to [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet.

Subgraph Studio lets you create, manage, deploy, and publish subgraphs, as well as create and manage API keys.

Click "Create a Subgraph". It is recommended to name the subgraph in Title Case: "Subgraph Name Chain Name".

### 2. Install the Graph CLI

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

Expand All @@ -29,40 +37,19 @@ Using [yarn](https://yarnpkg.com/):
yarn global add @graphprotocol/graph-cli
```

### 2. Create your subgraph

If your contract has events, the `init` command will automatically create a scaffold of a subgraph.

#### Create via Graph CLI

Use the following command to create a subgraph in Subgraph Studio using the CLI:

```sh
graph init --product subgraph-studio
```

#### Create via Subgraph Studio

Subgraph Studio lets you create, manage, deploy, and publish subgraphs, as well as create and manage API keys.

1. Go to [Subgraph Studio](https://thegraph.com/studio/) and connect your wallet.
2. Click "Create a Subgraph". It is recommended to name the subgraph in Title Case: "Subgraph Name Chain Name".

For additional information on subgraph creation and the Graph CLI, see [Creating a Subgraph](/developing/creating-a-subgraph).

### 3. Initialize your subgraph

#### From an existing contract
> You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
The `graph init` command will automatically create a scaffold of a subgraph based on your contract's events.

The following command initializes your subgraph from an existing contract:

```sh
graph init <SUBGRAPH_SLUG>
graph init
```

> Note: If your contract was verified on Etherscan, then the ABI will automatically be created in the CLI.
You can find commands for your specific subgraph on the subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
If your contract was verified on Etherscan, then the ABI will automatically be created in the CLI.

When you initialize your subgraph, the CLI will ask you for the following information:

Expand All @@ -81,7 +68,7 @@ See the following screenshot for an example for what to expect when initializing

![Subgraph command](/img/CLI-Example.png)

### 4. Write your subgraph
### 4. Edit your subgraph

The `init` command in the previous step creates a scaffold subgraph that you can use as a starting point to build your subgraph.

Expand All @@ -97,17 +84,17 @@ For a detailed breakdown on how to write your subgraph, check out [Creating a Su

Remember, deploying is not the same as publishing.

- When you deploy a subgraph, you push it to [Subgraph Studio](https://thegraph.com/studio/), where you can test, stage and review it.
- When you publish a subgraph, you are publishing it onchain to the decentralized network.
When you deploy a subgraph, you push it to [Subgraph Studio](https://thegraph.com/studio/), where you can test, stage and review it.

1. Once your subgraph is written, run the following commands:
When you publish a subgraph, you are publishing it onchain to the decentralized network.

Once your subgraph is written, run the following commands:

```sh
graph codegen
graph build
graph codegen && graph build
```

2. Authenticate and deploy your subgraph. The deploy key can be found on the subgraph's page in Subgraph Studio.
Authenticate and deploy your subgraph. The deploy key can be found on the subgraph's page in Subgraph Studio.

![Deploy key](/img/subgraph-studio-deploy-key.jpg)

Expand All @@ -118,12 +105,11 @@ Remember, deploying is not the same as publishing.
graph deploy <SUBGRAPH_SLUG>
```

- The CLI will ask for a version label.
- 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.
The CLI will ask for a version label. It's strongly recommended to use [semantic versioning](https://semver.org/), e.g. `0.0.1`.

### 6. Review your subgraph

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:
If you’d like to test your subgraph before publishing it, you can use [Subgraph Studio](https://thegraph.com/studio/) to do the following:

- Run a sample query.
- Analyze your subgraph in the dashboard to check information.
Expand All @@ -133,19 +119,23 @@ If you’d like to examine your subgraph before publishing it to the network, yo

### 7. Publish your subgraph to The Graph Network

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.
Publishing a subgraph to the decentralized network is an onchain action that makes your subgraph available for [Curators](/network/curating/) to curate it and [Indexers](/network/indexing/) to index it.

#### Publishing with Subgraph Studio

1. To publish your subgraph, click the Publish button in the dashboard.
2. Select the network to which you would like to publish your subgraph.
To publish your subgraph, click the Publish button in the dashboard.

![Publish a subgraph on Subgraph Studio](/img/publish-sub-transfer.png)

Select the network to which you would like to publish your subgraph.

#### Publishing from the CLI

As of version 0.73.0, you can also publish your subgraph with the Graph CLI.

1. Open the `graph-cli`.
2. Use the following commands:
Open the `graph-cli`.

Use the following commands:

```sh
graph codegen && graph build
Expand All @@ -165,7 +155,7 @@ To customize your deployment, see [Publishing a Subgraph](/publishing/publishing

#### Adding signal to your subgraph

1. To attract indexers to query your subgraph, you should add GRT curation signal to it.
1. To attract Indexers to query your subgraph, you should add GRT curation signal to it.

- This action improves quality of service, reduces latency, and enhances network redundancy and availability for your subgraph.

Expand All @@ -181,6 +171,8 @@ To save on gas costs, you can curate your subgraph in the same transaction you p

### 8. Query your subgraph

Now, you can query your subgraph by sending GraphQL queries to its Query URL, which you can find by clicking the Query button.
You now have access to 100,000 free queries per month with your subgraph on The Graph Network!

You can query your subgraph by sending GraphQL queries to its Query URL, which you can find by clicking the Query button.

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