# 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>
