# Query Layer

## Indexing  Service

We leverage Airstack  (<https://www.airstack.xyz/>) to create an aggregated look at the underlying Polygon blockchain.

{% hint style="info" %}
**Just so you know:** This API is exposed to anyone who wants to build apps or visuals using the CropXYZ data can pull aggregated on-chain data.
{% endhint %}

### Sample Requests

For the initial launch, we used The Graph so here are a set of sample requests that can be made to The Graph query layer. This is more for demonstrative purposes because this entire logic wil be from Airstack in this relaunch.

<details>

<summary>Overall Game State</summary>

All of the smart contracts report their pause status and contract address.

```
{
  gameStates(first: 20) {
    id
    address
    isPaused
  }
}
```

#### Query Link:

<https://thegraph.com/hosted-service/subgraph/cropxyz/cropxyz-metaverse?query=Game%20State>

</details>

<details>

<summary>Crops Details</summary>

This requests pulls the basic details of all crops as well as the time it takes to grow these crops.

```
{
  crops {
    elementName
    addressMapping {
      tokenAddress
    }
    plotType {
      name
    }
    growthTimeTable {
      deltaNothingToStart
      deltaStartToEarly
      deltaEarlyToMature
      deltaMatureToExpire
    }
  }
}
```

#### Query Link:

<https://thegraph.com/hosted-service/subgraph/cropxyz/cropxyz-metaverse?query=Crops>

</details>

<details>

<summary>Plots</summary>

This request pulls the base details about the plots, also it pulls the planted crop (if one has been planted).

```
{
    plots(first: 1000, skip: 0) {
      id
      width
      height
      tileArea
      baseSpeed
      baseYield
      countClears
      countHarvests
      countDeathClears
      baseYield
      yieldConfig {
        minYield
        maxYield
      }
      stakedCrop {
        id
        elementName
        addressMapping {
          addressName
          tokenAddress
        }
      }
      plotType {
        id
        name
      }
      amountStaked
      timeStartStaked
      timeReadyDelta
      timeExpiredDelta
    }
}
```

#### Query Link:

<https://thegraph.com/hosted-service/subgraph/cropxyz/cropxyz-metaverse?query=Plots>

</details>

<details>

<summary>Plot Actions</summary>

The plot actions are the different plots, harvests and clear actions players take on their plot.

```
{
  plotActions(first: 1000, skip: 0) {
    id
    timestamp
    blockIndex
    playerAddress
    amount
    actionType
    plot {
      id
    }
    currentCrop {
      elementName
      addressMapping {
        tokenAddress
      }
    }
    newCrop {
      elementName
      addressMapping {
        tokenAddress
      }
    }
  }
}
```

#### Query Link:

<https://thegraph.com/hosted-service/subgraph/cropxyz/cropxyz-metaverse?query=Plot%20Actions>

</details>

<details>

<summary>Transactions</summary>

Each transaction is broken up into the seeds or gold flowing "in" to the economic layer and how much gold or seed flows "out" of the economic layer.

```
{
  transactionFlows(first: 1000, skip: 0) {
    timestamp
    blockIndex
    playerAddress
    isGoldInbound
    flowIn {
      tokenAddress
      tokenAmount
    }
    flowOut {
      tokenAddress
      tokenAmount
    }
  }
}
```

#### Query Link:

<https://thegraph.com/hosted-service/subgraph/cropxyz/cropxyz-metaverse?query=Game%20State>

</details>


---

# Agent Instructions: 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:

```
GET https://docs.cropxyz.com/tech/query-layer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
