> For the complete documentation index, see [llms.txt](https://docs.carv.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.carv.io/carv-ecosystem/carv-play/carv-intro/api-verified-quest-graphql.md).

# API-Verified Quest (GraphQL)

## Introduction

GraphQL verification takes a single wallet address or email as input and outputs 0(false)/1(true) to indicate whether the wallet address is eligible. It requires 3 fields to be filled in: **GraphQL Endpoint (HTTPs)**, **Query** and **Expression**.

## Sequence Diagram

<figure><img src="/files/gYosVRyAiX08oTqMsmaS" alt=""><figcaption></figcaption></figure>

## GraphQL Endpoint (HTTPs)

It's the HTTPs endpoint where Subgraph queries go to, see the example below.&#x20;

{% hint style="warning" %}
NOTE: If you saw an error when testing the API, check if the endpoint is a valid GraphQL API endpoint. Common misconfigurations include:

* &#x20;Incorrectly used a GraphQL *playground* url, that usually ends with `/graph`
* &#x20;The GraphQL endpoint does now allow CORS from carv.io.
  {% endhint %}

## Query

The GraphQL query requires a single wallet address as input. In the dashboard, once you finish your query, fill in a test address and click 'Run' button to check if the query's return is good.

## Expression

A JavaScript (ES6) function with this type signature: `(object) => int`. The function must be anonymous, which means that the first line of the expression should be like `function(data) {`, instead of `let expression = (data) => {`.

The function should return either number 1 or 0, representing if the address has completed the quest. Behind the scenes, first, we send the query with the user's address to the GraphQL endpoint, and then we will apply the function against the 'data' field of the response. If the returned value is 1, then user is considered to have completed this quest, otherwise not.

Once the query's output is good, click 'Run' button to check if expression processes the query's output correctly.

## Subgraph Examples

**Endpoint**

```
https://api.thegraph.com/subgraphs/name/carv-protocol/carvachievementsonbnb
```

**Query**

```graphql
query info($address: String!) {
  # write you query here 
    erc1155Balances(
    first: 1
    where: {token_: {identifier: "1"}, account_: {id: $address}}
  ) {
    account {
      id
    }
    token {
      id
      identifier
    }
  }
}

# test address: 0x357A5eE000B5cA0935Aad7bb4Cb96E8AcAf46727
```

**Query Output**

```json
{
  "erc1155Balances": [
    {
      "account": {
        "id": "0x357a5ee000b5ca0935aad7bb4cb96e8acaf46727"
      },
      "token": {
        "id": "0xc2f24ffe96a69e381a747dc73fcd51492e29a0a4/0x1",
        "identifier": "1"
      }
    }
  ]
}
```

**Expression**

```javascript
function verify(data){
    if (data.erc1155Balances.length > 0){
        return true
    } else {
        return false
    }
}
```

**Expression Output**

```
true
```


---

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

```
GET https://docs.carv.io/carv-ecosystem/carv-play/carv-intro/api-verified-quest-graphql.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.
