# Subgraph

Subgraphs are our read-only APIs that subscribe to our on-chain events and construct easy-to-consume entities for clients.&#x20;

The subgraphs urls are network specific and following the following template

* **API:** <https://api.thegraph.com/subgraphs/name/otterspace-xyz/badges-\\[network-name>]
* **Interactive:** <https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-\\[network-name>]

<table data-full-width="false"><thead><tr><th width="179">Network</th><th>Subgraph</th></tr></thead><tbody><tr><td>Optimism</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism</a></td></tr><tr><td>Mainnet</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-mainnet">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-mainnet</a></td></tr><tr><td>Polygon</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-polygon">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-polygon</a></td></tr><tr><td>Goerli</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-goerli">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-goerli</a></td></tr><tr><td>Optimism Goerli</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism-goerli">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism-goerli</a></td></tr></tbody></table>

### Get a list of communities

```graphql
{
  rafts(where: {totalSpecsCount_gt: 0}) {
    id
    metadata {
      name
    }
    totalSpecsCount
    totalBadgesCount
    specs {
      metadata {
        name
      }
      totalBadgesCount
    }
  }
}
```

### Get active badges of a community

```graphql
{
  badges(
    where: { 
      spec_: { 
        raft: "rafts:1"
      } 
      status_in: ["MINTED", "REINSTATED"]
    } 
  ) {
    id
    owner
    status
    createdAt
    spec {
      metadata { 
        name
        expiresAt
      }
    }
  }
}
```

### Get all the badge specs of a community

```graphql
{
  raft(id: "rafts:1") {
    id
    metadata {
      name
    }
    totalSpecsCount
    totalBadgesCount
    specs {
      uri
      totalBadgesCount
      metadata {
        name
      }
    }
  }
}
```

### Get all the owners of a badge

```graphql
{
  badgeSpec(id: "bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e") {
    id
    metadata {
      name
      description
      image
      expiresAt
    }
    totalBadgesCount
    badges {
      id
      owner
      status
      createdAt
    }
  }
}
```

### Get badges owned by an address

```graphql
{
  badges(where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4"}) {
    id
    createdAt
    status
    spec {
      id
      metadata {
        name
        description
        expiresAt
        image
      }
      raft {
        id
        metadata {
          name
          image
        }
      }
    }
  }
}
```

### Check if an address owns a certain badge

```graphql
{
  badges(
    where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4", spec_in: ["bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e", "bafyreia2lnu2jmr6sqqijzd3xt6fw2qriyy2vbq57zikzrkeyxfvlpqp3i"]}
  ) {
    id
    owner
    status
    createdAt
  }
}
```


---

# 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.otterspace.xyz/documentation/subgraph.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.
