Blockchain Indexer
Blockchain Indexer: Deploying a Subgraph
Section titled “Blockchain Indexer: Deploying a Subgraph”Part 1: Introduction
Section titled “Part 1: Introduction”This tutorial will guide you through deploying an already initialized subgraph tailored for the Moonchain NFT Marketplace Smart Contract on the Hudson Testnet using The Graph.
Overview of The Graph
Section titled “Overview of The Graph”The Graph allows developers to query blockchain data easily using GraphQL. It provides powerful tools to index blockchain data and serve it through a GraphQL endpoint, enabling efficient data access for decentralized applications.
To get started with deploying our pre-initialized subgraph on the Hudson Testnet, follow the steps below:
Prerequisites
Section titled “Prerequisites”1. Clone the Repository: First, clone the repository and switch to the Hudson
branch.
git clone --branch Hudson https://github.com/JDI-Group/MCH-nft-graph.gitcd MCH-nft-graph
2. Install Required Packages: Install the necessary packages.
yarn add global package.json
Steps for Deployment
Section titled “Steps for Deployment”Note
In this tutorial section, we omit the ‘init’ command typically used to initialize a new subgraph. This is because Hudson Testnet and similar non-standard networks are not supported by the standard init command of The Graph. Instead, we focus on generating the subgraph code directly from the existing schema.
Part 2: Deployment
Section titled “Part 2: Deployment”Please refer to Moonchain Chains Overview for advanced configurations and specific setup instructions tailored to non-standard networks like the Hudson Testnet.
1. Code Generation: Generate the subgraph code.
graph codegen
2. Build the Subgraph: Build and compile the subgraph.
graph build
3. Create the Subgraph: Generate the subgraph code, replacing <SUBGRAPH-NAME>
with the actual name of your subgraph.
graph create --node http://Hudson-graph-node.mchain.ai:8020/ <SUBGRAPH-NAME>
4. Deploy the Subgraph: Deploy the subgraph using graph deploy
to the Hudson Testnet node specified. Again, replace <SUBGRAPH-NAME>
with the actual name of your subgraph.
graph deploy --node http://Hudson-graph-node.mchain.ai:8020/ <SUBGRAPH-NAME>
Upon successful deployment, you will receive the URL where you can interact with your Moonchain NFT Marketplace subgraph.
Conclusion
Section titled “Conclusion”Use GraphQL queries such as the following example to explore and utilize the capabilities of your deployed subgraph.
query { marketplaceOrderInfos { id assetId seller nftAddress blockNumber blockTimestamp transactionHash event priceInWei expiresAt totalPrice buyer }}
This query retrieves information about orders made on the marketplace, demonstrating how you can leverage your subgraph to access and analyze marketplace order data effectively on the Hudson Testnet.