This repository contains the subgraphs of the znft eco-system. Subgraphs are prelminarily used for the purpose of making querying on blockchain much more faster & quicker.
- GRAPH PROTOCOL - Subgraph Protocol we're using
- TypeScript - Handler Functions are programmed in TS
- GraphQL - Queries are written in GraphQL
- YAML - Configuration Files written in YAML
- GRAPH CLI - Graph CLI for development
The repository is built using typescript.Also the development of these smart contracts are done in npm version 7.16.0 & NodeJs version 16.1.0. If it returns invalid response then you should install node and npm before proceeding further. Installation of graph cli as global module is also required.
Verify installation using
npm -v && node -v
Installing Graph CLI
npm install -g @graphprotocol/graph-cli
Step by step instructions on setting up the project and running it
-
Clone the repository
git clone https://github.com/znftmarket/znft-subgraphs -
Install Dependencies
npm install -
Generating Codegen Files after editing subgraph.yaml file
npm run codegenorgraph codegenMake sure you install graph-cli globally before running this command.
-
Building the Subgraph before deployment
npm run buildorgraph buildMake sure you install graph-cli globally before running this command.
-
Deploying Sub graphs to hosted provider
npm run deployThis command is for deploying the subgraphs to a hosted network. If the above command throws error due to TS compatibility try running
graph deploy znftmarket/znft-kovan --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/
For deploying the Subgraphs you've to create a project in the thegraph.com. For that you've to sign-in with your GitHub account & create a project inside the dashboard. Once you created the project, follow the below steps to deploy your subgraph to that project.
-
Set the auth token. (On your dashboard you'll get your authtoken). Replace YOUR-AUTH-TOKEN with the token from the dashboard.
graph auth https://api.thegraph.com/deploy/ <YOUR-AUTH-TOKEN> -
Replace the project name in the package.json deploy script. Replace NAME-OF-PROJECT with the name of the project you've created in the graph dashboard.
The deployment script should be
graph deploy <NAME-OF-PROJECT> --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ -
Run the following command to deploy your subgraph to the new project.
npm run deployorgraph deploy <NAME-OF-PROJECT> --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/Replace the NAME-OF-PROJECT to the name of the project you've created in the graph dashboard.
-
All Configuration Files can be found at subgraph.yaml file.
-
All Schema Declarations can be found at schema.graphql file.
-
Event handlers can be found under the folder /src. 3.1 Each smart contract will have a file named after them. There are 4 smart contracts and there should be 4 mapping files inside the src folder.
-
ABIs are found inside the folder /abis.
If a smart contract or event is editted then the subgraph.yaml file and the ABI of the contract should've to be changed. They're named after them.
All configuration is done in subgraph.yaml file.
This query fetches all the auctions created and their information.
{
auctions(first: 5) {
id
tokenId
starts
ends
highestBid
highestBidder
isSettled
}
}Querying for specific auction info
{
auctions(where: {auctionId : <auctionId>}) {
id
tokenId
starts
ends
highestBid
highestBidder
isSettled
}
}
All available schema and queries can be found there Graph Explorer