Skip to main content

The Graph

What is the graph? The Graph is an indexing protocol for querying blockchain and IPFS data that exposes a richer query layer for apps to consume.

It's difficult and time-intensive to read data directly from the chain.

Benefit

Engineering teams could architect a centralized indexing database and serve API requests from these servers but this:

  1. requires expert engineering knowledge
  2. requires setup hardware resources
  3. breaks the security properties of decentralization

Config

  1. Create an account
  2. Create a subgraph
  3. Install the Cli
 yarn global add @graphprotocol/graph-cli

Init the project from a deployed contract.

graph init --from-contract CONTRACT-ADDRESS --network mumbai --contract-name Blog --index-events

Dev Flow

  • Define Entities
  • graph codegen
  • update subgraph.yaml
  • get start block from polygonscan.com
  • enter startBlock into subgraph.yaml
  • update src/mappings
  • graph build
  • graph auth
  • yarn deploy
  • query subgraph
  • optimise app queries