This repository contains the subgraph for the Guestbook application on the Core Network. The subgraph indexes events and data from the Guestbook smart contract, allowing for easy querying using GraphQL.
- Prerequisites
- Clone the Repository
- Configuration
- Install Dependencies
- Deploying with Docker
- Deploying the Subgraph
- Interacting with the Subgraph
- Troubleshooting
Before you begin, ensure you have the following installed:
To clone the repository locally, run the following commands:
git clone https://github.com/coredao-org/dapp-tutorial.git
cd dapp-tutorial/06-Subgraphs-on-CoreYou need to set up the following environment variables to configure deployment:
Create a .env file in the root directory:
touch.env- Add the necessary environment variables to the .env file:
GRAPH_NODE=https://thegraph-node.test.btcs.network/
IPFS_NODE=https://thegraph-ipfs.test.btcs.network/
GRAPH_ACCESS_TOKEN=your_access_token_hereEnsure your subgraph.yaml file is correctly set up with the necessary contract addresses and start blocks.
npm installThis will install all required packages including @graphprotocol/graph-cli and @graphprotocol/graph-ts.
You can deploy your subgraph using Docker to simulate a local environment.
- Build and Start Docker Containers:
docker-compose up -d- Check Docker Containers:
docker psEnsure all necessary containers are running.
If not already authenticated, authenticate your deployment key:
export GRAPH_ACCESS_TOKEN=08e38ec0513b40fd9b6a4428923d06acgraph codegen
graph buildgraph create \
--node $GRAPH_NODE \
--access-token $GRAPH_ACCESS_TOKEN \
your-subgraph-name
graph deploy \
--node $GRAPH_NODE \
--ipfs $IPFS_NODE \
--access-token $GRAPH_ACCESS_TOKEN \
your-subgraph-name
Replace your-subgraph-name with your deployment target.
After deployment, your subgraph will be available at the query endpoint (e.g., https://thegraph.test2.btcs.network/subgraphs/name/guestbook-subgraph).
Example query:
{
entrySigneds(first: 10, orderBy: blockTimestamp, orderDirection: desc) {
id
name
message
blockNumber
blockTimestamp
transactionHash
}
}
You can use GraphQL, Apollo Client, or any GraphQL tool to query your data.