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:
- requires expert engineering knowledge
- requires setup hardware resources
- breaks the security properties of decentralization
Config
- Create an account
- Create a subgraph
- 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