The Hedera Subgraph Example Project demonstrates how to create and deploy a subgraph to a local graph node using The Graph Protocol. Based on the Hedera Hardhat Example Project Repo. For more information about subgraphs, check out The Graph Protocol documentation here.
🔥 Check out the step-by-step tutorial here.
-
docker.compose.yaml- The configuration file that's used by Docker Compose to define and run containers that make up your local graph node. This file specifies settings, including container images, environment variables, and network configuration. -
subgraph.yaml- The Graph configuration file to specify the schema and data that the subgraph indexes and makes available for querying. -
schema.graphql- The GraphQL schema for the subgrapg, defining the types of data that can be queried, relationship between entities, and specifies the fields that can be queried. -
mappings.ts- The file that contains the mapping function that translates the events emitted by your smart contract into GraphQL entities that the subgraph can index. -
/generated- The auto-generated folder by The Graph's CLI tooling and contains JSON ABIs, a GraphQL schema, and TypeScript and AssemblyScript types used to interface with your smart contract and subgraph.
- Clone this repo to your local machine:
git clone https://github.com/hashgraph/hedera-subgraph-example.git- Once you've cloned the repository, open your IDE terminal and navigate to the root directory of the project and change directories:
cd hedera-subgraph-example- Once you've cloned the repository, open your IDE terminal and navigate to the root directory of your project. Run the following command to install all the necessary dependencies:
npm install-
Rename the
subgraph.template.yamlfile tosubgraph.yaml. -
Add the deployed Greeter contract address to the
addressproperty and the start block number to thestartBlockproperty in thesubgraph.yamlfile. -
Add the Hashio Testnet API endpoint URL to the
ethereumfield under theenvironmentobject inside thedocker-compose.yamlfile. -
Start the local graph node:
npm run graph-node- Generate the AssemblyScript types:
graph codegen- Create the subgraph:
npm run create-local- Deploy the subgraph:
npm run deploy-local
Once the node finishes indexing, you will be able to access the GraphQL API at: http://localhost:8000/subgraphs/name/Greeter
Contributions are welcome. Please see the contributing guide to see how you can get involved.
This project is governed by the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to oss@hedera.com.