> For the complete documentation index, see [llms.txt](https://xai-foundation.gitbook.io/xai-network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xai-foundation.gitbook.io/xai-network/kn/xai-gaming-dev-resources/subgraph.md).

# Subgraph

Goldsky is a powerful subgraph provider that allows game developers to efficiently query blockchain data on Xai. By leveraging Goldsky, you can access real-time data for both the testnet and mainnet environments, enabling seamless integration and enhanced functionality for your games.

**Why Use Goldsky Subgraphs?**

Subgraphs are essential for indexing and querying blockchain data quickly and efficiently. Goldsky provides robust and scalable subgraph solutions, making it easier to interact with complex blockchain data structures. Key benefits include:

* **Real-time Data Access:** Obtain up-to-date information from the blockchain, ensuring your game logic remains current and accurate.
* **Efficient Queries:** Optimize your data retrieval processes with high-performance querying capabilities.
* **Seamless Integration:** Easily integrate subgraph data into your game development workflows.

**Accessing Goldsky Subgraphs**

Goldsky provides endpoints for both the Xai testnet and mainnet, allowing you to test and deploy your game with reliable data sources.

**Testnet Subgraph**

To access the Xai testnet subgraph, use the following endpoint:

```bash
bashCopy codehttps://api.goldsky.com/api/public/project_cl8ylkiw00krx0hvza0qw17vn/subgraphs/blocks/xai-sepolia/gn
```

This endpoint provides access to testnet data, enabling you to develop and test your game in a safe environment before deploying to mainnet.

**Mainnet Subgraph**

For live data on the Xai mainnet, use this endpoint:

```bash
bashCopy codehttps://api.goldsky.com/api/public/project_cl8ylkiw00krx0hvza0qw17vn/subgraphs/blocks/xai/gn
```

This endpoint ensures you can access real-time mainnet data, crucial for deploying your game to production with accurate and reliable information.

**How to Use Goldsky Subgraphs**

1. **Setup Your Environment:** Ensure your development environment is configured to make HTTP requests. Common tools include cURL, Postman, or integrated directly within your codebase using libraries like Axios (JavaScript) or Requests (Python).
2. **Querying Data:** Construct your GraphQL queries to fetch the necessary data from the subgraphs. Here is a basic example of a GraphQL query to get block information:

   ```graphql
   graphqlCopy code{
     blocks(first: 5) {
       id
       number
       timestamp
     }
   }
   ```
3. **Integrating into Your Game:** Use the data retrieved from Goldsky subgraphs to enhance your game logic. Whether you need player stats, game state information, or other blockchain-related data, subgraphs provide a reliable source.
4. **Testing:** Always test your queries on the testnet first to ensure they return the expected data. Once validated, you can confidently switch to the mainnet endpoint for production.

**Additional Resources**

For more detailed information and advanced usage, refer to the Goldsky documentation:

* [Goldsky Documentation](https://docs.goldsky.com/chains/xai)

By leveraging Goldsky subgraphs, you can build more dynamic, data-driven games on the Xai blockchain, ensuring a smooth and enriched gaming experience for your users.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xai-foundation.gitbook.io/xai-network/kn/xai-gaming-dev-resources/subgraph.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
