Skip to main content
When you build a dApp, it can be difficult to get historical data for a smart contract. The Graph gives you an easy way to query smart contract data through APIs called subgraphs. The Graph’s infrastructure relies on a decentralized network of indexers. This lets your dApp be fully decentralized.

Quick start

A subgraph takes only a few minutes to set up. To get started, follow these three steps:
  1. Initialize your subgraph project
  2. Deploy and publish
  3. Query from your dApp
Pricing: All developers get 100K free queries per month on the decentralized network. After these free queries, you pay only for usage, at $4 for every 100K queries.

1. Initialize your subgraph project

Create a subgraph on Subgraph Studio⁠

Go to the Subgraph Studio and connect your wallet. Then click Create a Subgraph. When you enter the subgraph name, use Title Case: “Subgraph Name Chain Name.” Create a Subgraph Create a Subgraph Your subgraph’s page then opens. The right side of the page shows all the CLI commands that you need: CLI commands CLI Commands

Install the Graph CLI⁠

On your local machine, run this command:

Initialize your subgraph⁠

You can copy this command from your subgraph page. The copied command includes your subgraph slug:
The CLI then prompts you for some information about your subgraph: CLI sample CLI Make sure that your contract is verified on the block explorer. The CLI then gets the ABI automatically and sets up your subgraph. The default settings generate an entity for each event.

2. Deploy & publish

Deploy to Subgraph Studio⁠

First, run these commands:
Then run these commands to authenticate and deploy your subgraph. You can copy them from your subgraph’s page in Studio. The copied commands include your deploy key and subgraph slug:
The CLI asks for a version label. You can enter something like v0.0.1, but you can choose any format.

Test your subgraph⁠

You can test your subgraph with a sample query in the playground section. The Details tab shows an API endpoint. You can use that endpoint to test from your dApp. Playground Run your GraphQL query in Studio

Publish your subgraph to The Graph’s decentralized network

When your subgraph is ready for production, you can publish it to the decentralized network. On your subgraph’s page in Subgraph Studio, click Publish: Publish button Click Publish Before you can query your subgraph, Indexers need to start serving queries on it. To speed up this process, you can curate your own subgraph with GRT. When you publish, you see the option to curate your subgraph. Signaling GRT on your own subgraph helps make sure that it is indexed and available for queries as soon as possible. For current guidance on how much GRT to signal, see The Graph’s curating documentation. Publish screen Publish screen
The Graph’s smart contracts are all on Arbitrum One, even if your subgraph indexes data from Ethereum, BSC, or any other supported chain.

3. Query your subgraph

To query any subgraph on the decentralized network, pass a GraphQL query to the subgraph’s query URL. You can find the query URL at the top of the subgraph’s Explorer page. This example is from the CryptoPunks Ethereum subgraph by Messari: Query URL Query URL The query URL for this subgraph is: https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/HdVdERFUe8h61vm2fDyycHgxjsde5PbB832NHgJfZNqK To send GraphQL queries to this endpoint, fill in your own API key.

Getting your own API key

API keys API keys In Subgraph Studio, the API Keys menu is at the top of the page. You can create API keys there.

Appendix

Sample query

This query shows the most expensive CryptoPunks sold.
If you pass this query to the query URL, it returns this result:
Trivia: The top sales list on the CryptoPunks website shows Punk #5822 as the top sale, not #9998. The reason is that the website censors the flash-loan sale.

Sample code

Additional resources:

  • To learn the ways that you can optimize and customize your subgraph for better performance, read about creating a subgraph.
  • For more information about how to query data from your subgraph, see the querying documentation.