The Graph
Getting historical data on a smart contract can be frustrating when building a dApp. The Graph provides an easy way to query smart contract data through APIs known as subgraphs, which utilize GraphQL
. The Graph's infrastructure relies on a decentralized network of indexers, enabling your dApp to become truly decentralized.
Quick start
These subgraphs only take a few minutes to set up and get running. To get started, follow these three steps:
Pricing: All developers receive 100K free monthly queries on the decentralized network. After these free queries, you only pay based on usage at $4 for every 100K queries.
Here's a step by step walkthrough:
1. Initialize your subgraph project
Create a subgraph on Subgraph Studio
Go to the Subgraph Studio and connect your wallet. Once your wallet is connected, you can begin by clicking "Create a Subgraph". Please choose a good name for the subgraph: this name can't be edited later. It is recommended to use Title Case: "Subgraph Name Chain Name."
You will then land on your subgraph's page. All the CLI commands you need will be visible on the right side of the page:
Install the Graph CLI
On your local machine, run the following:
npm install -g @graphprotocol/graph-cli
Initialize your Subgraph
You can copy this directly from your subgraph page to include your specific subgraph slug:
graph init --studio <SUBGRAPH_SLUG>
You'll be prompted to provide some info on your subgraph like this:
Simply have your contract verified on the block explorer, and the CLI will automatically obtain the ABI and set up your subgraph. The default settings will generate an entity for each event.