Skip to content

Quickstart edits #926

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

Merged
merged 3 commits into from
Apr 10, 2025
Merged
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
94 changes: 27 additions & 67 deletions website/src/pages/en/subgraphs/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
title: Quick Start
---

Learn how to easily build, publish and query a [Subgraph](/subgraphs/developing/developer-faq/#1-what-is-a-subgraph) on The Graph.
Create, deploy, and query a [Subgraph](/subgraphs/developing/developer-faq/#1-what-is-a-subgraph) on The Graph Network.

By the end, you'll have:

- Initialized a Subgraph from a smart contract
- Deployed it to Subgraph Studio for testing
- Published to The Graph Network for decentralized indexing

## Prerequisites

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

## How to Build a Subgraph

### 1. Create a Subgraph in Subgraph Studio

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".
1. Go to [Subgraph Studio](https://thegraph.com/studio/)
2. Connect your wallet
3. Click "Create a Subgraph"
4. Name it in Title Case: "Subgraph Name Chain Name"

### 2. Install the Graph CLI

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

### 3. Initialize your Subgraph
Verify install:

> You can find commands for your specific Subgraph on the Subgraph page in [Subgraph Studio](https://thegraph.com/studio/).
```sh
graph --version
```

### 3. Initialize your Subgraph

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

The following command initializes your Subgraph from an existing contract:
The following command initializes your Subgraph from an existing contract and indexes events:

```sh
graph init
```

If your contract is verified on the respective blockscanner where it is deployed (such as [Etherscan](https://etherscan.io/)), then the ABI will automatically be created in the CLI.

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

- **Protocol**: Choose the protocol your Subgraph will be indexing data from.
Expand All @@ -59,19 +65,17 @@ When you initialize your Subgraph, the CLI will ask you for the following inform
- **Ethereum network** (optional): You may need to specify which EVM-compatible network your Subgraph will be indexing data from.
- **Contract address**: Locate the smart contract address you’d like to query data from.
- **ABI**: If the ABI is not auto-populated, you will need to input it manually as a JSON file.
- **Start Block**: You should input the start block to optimize Subgraph indexing of blockchain data. Locate the start block by finding the block where your contract was deployed.
- **Start Block**: You should input the start block where the contract was deployed to optimize Subgraph indexing of blockchain data.
- **Contract Name**: Input the name of your contract.
- **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.
- **Add another contract** (optional): You can add another contract.

See the following screenshot for an example for what to expect when initializing your Subgraph:
See the following screenshot for an example of what to expect when initializing your Subgraph:

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

### 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.

When making changes to the Subgraph, you will mainly work with three files:

- Manifest (`subgraph.yaml`) - defines what data sources your Subgraph will index.
Expand All @@ -82,9 +86,7 @@ For a detailed breakdown on how to write your Subgraph, check out [Creating a Su

### 5. Deploy your Subgraph

> 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. A deployed Subgraph's indexing is performed by the [Upgrade Indexer](https://thegraph.com/blog/upgrade-indexer/), which is a single Indexer owned and operated by Edge & Node, rather than by the many decentralized Indexers in The Graph Network. A **deployed** Subgraph is free to use, rate-limited, not visible to the public, and meant to be used for development, staging, and testing purposes.
When you **deploy** a Subgraph, you push it to [Subgraph Studio](https://thegraph.com/studio/), where you can test, stage and review it. A deployed Subgraph's indexing is performed by the [Upgrade Indexer](https://thegraph.com/blog/upgrade-indexer/), which is a single Indexer owned and operated by Edge & Node. A **deployed** Subgraph is free to use, rate-limited, not visible to the public, and meant to be used for development, staging, and testing purposes.

Once your Subgraph is written, run the following commands:

Expand All @@ -103,8 +105,6 @@ Authenticate and deploy your Subgraph. The deploy key can be found on the Subgra
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`.

### 6. Review your Subgraph

If you’d like to test your Subgraph before publishing it, you can use [Subgraph Studio](https://thegraph.com/studio/) to do the following:
Expand All @@ -121,53 +121,13 @@ When your Subgraph is ready for a production environment, you can publish it to

- It makes your Subgraph available to be to indexed by the decentralized [Indexers](/indexing/overview/) on The Graph Network.
- It removes rate limits and makes your Subgraph publicly searchable and queryable in [Graph Explorer](https://thegraph.com/explorer/).
- It makes your Subgraph available for [Curators](/resources/roles/curating/) to curate it.

> The greater the amount of GRT you and others curate on your Subgraph, the more Indexers will be incentivized to index your Subgraph, improving the quality of service, reducing latency, and enhancing network redundancy for your Subgraph.
- It makes your Subgraph available for [Curators](/resources/roles/curating/) to add curation signal.

#### Publishing with Subgraph Studio

To publish your Subgraph, click the Publish button in the dashboard.
To publish your Subgraph, click the Publish button in the dashboard and select your network.

![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.

Open the `graph-cli`.

Use the following commands:

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

Then,

```sh
graph publish
```

3. A window will open, allowing you to connect your wallet, add metadata, and deploy your finalized Subgraph to a network of your choice.

![cli-ui](/img/cli-ui.png)

To customize your deployment, see [Publishing a Subgraph](/subgraphs/developing/publishing/publishing-a-subgraph/).

#### Adding signal to your Subgraph

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.

2. If eligible for indexing rewards, Indexers receive GRT rewards based on the signaled amount.

- It’s recommended to curate at least 3,000 GRT to attract 3 Indexers. Check reward eligibility based on Subgraph feature usage and supported networks.

To learn more about curation, read [Curating](/resources/roles/curating/).
> It is recommended that you curate your own Subgraph with at least 3,000 GRT to incentivize indexing.

To save on gas costs, you can curate your Subgraph in the same transaction you publish it by selecting this option:

Expand Down