# API Documentation

If you'd prefer to use our existing API (offered at best effort) instead of building your own, you can use the endpoints shown below.

The API for WAX Mainnet is:

```html
https://token-farms.waxdaobp.io
```

All endpoints return data in JSON format.

### Quick Links

[#get-farm](#get-farm "mention")

[#get-farms](#get-farms "mention")

[#get-stakers](#get-stakers "mention")

[#staked-only](#staked-only "mention")

### Endpoint List

#### /get-farm

Method: POST

{% hint style="info" %}
Returns details about a single token farm
{% endhint %}

| Param      | Type   | Description                                            |
| ---------- | ------ | ------------------------------------------------------ |
| farm\_name | string | The 1 to 12 character farm name to get the details for |

```javascript
// Example

const farm_name = "mywaxdaofarm";

const getFarmSingle = async (farm_name) => {
  for (const api of network.endpoints.tokenfarms) {
    try {
      const res = await axios.post(
        `${api}/get-farm`,
        {
          farm_name: farm_name,
          json: true,
        },
        {
          headers: {
            "Access-Control-Allow-Origin": "*",
            "Content-Type": "application/json",
          },
        }
      );

      if (res?.data?.farm) {
        return res.data.farm;
      }
    } catch (error) {
      console.log(`Failed getting single farm from ${api}. Error: ${error}`);
      return [];
    }

    return [];
  }
};
```

#### /get-farms

Method: POST

{% hint style="info" %}
Returns data for multiple farms
{% endhint %}

| Param             | Type              | Description                                                                                                                                                                                                                                                          |
| ----------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| page              | int (optional)    | Which page of results you want to fetch. Default is 1                                                                                                                                                                                                                |
| limit             | int (optional)    | The amount of farms you want to fetch. Default: 100, Min: 1, Max: 100                                                                                                                                                                                                |
| sort              | string (optional) | How you want the farms sorted when they are returned. Options are `newest` and `oldest`. Default is `newest`                                                                                                                                                         |
| creator           | string (optional) | The WAX address of the account that created the farms.                                                                                                                                                                                                               |
| original\_creator | string (optional) | The WAX address of the original creator of the farm, this is applicable if you are using our partner contract. Your partner contract would be `creator` since it acts as a proxy, but `original_creator` would be the end user who set up the farm on your platform. |

```javascript
// Example

const partner = "prtnr.waxdao";

export const getFarmsByPartner = async (
  page = 1,
  limit = 100,
  sort = "newest"
) => {
  for (const api of network.endpoints.tokenfarms) {
    try {
      const res = await axios.post(
        `${api}/get-farms`,
        {
          creator: partner,
          page: page,
          limit: limit,
          sort: sort,
          json: true,
        },
        {
          headers: {
            "Access-Control-Allow-Origin": "*",
            "Content-Type": "application/json",
          },
        }
      );

      if (res?.data?.farms) {
        return res.data.farms;
      }
    } catch (error) {
      console.log(`Failed getting farms from ${api}. Error: ${error}`);
      return [];
    }
    return [];
  }
};
```

#### /get-stakers

Method: POST

{% hint style="info" %}
Returns a list of stakers (leaderboard) for a single farm. Sorted by most staked to least staked.
{% endhint %}

| Param      | Type           | Description                                                          |
| ---------- | -------------- | -------------------------------------------------------------------- |
| page       | int (optional) | Which page of results you want to fetch. Default is 1                |
| limit      | int (optional) | The amount of rows you want to fetch. Default: 100, Min: 1, Max: 100 |
| farm\_name | string         | The 1-12 character name of the farm you want to get the stakers for  |

```javascript
// Example

export const getStakersList = async (farm_name, page = 1, limit = 100) => {
  for (const api of network.endpoints.tokenfarms) {
    try {
      const res = await axios.post(
        `${api}/get-stakers`,
        {
          farm_name: farm_name,
          page: page,
          limit: limit,
          json: true,
        },
        {
          headers: {
            "Access-Control-Allow-Origin": "*",
            "Content-Type": "application/json",
          },
        }
      );

      if (res?.data?.stakers) {
        console.log(res.data.stakers);
        return res.data.stakers;
      }
    } catch (error) {
      console.log(`Failed getting stakers list from ${api}. Error: ${error}`);
      return [];
    }
    return [];
  }
};
```

#### /staked-only

Method: POST

{% hint style="info" %}
Returns a list of farms that a user is staking in.
{% endhint %}

| Param  | Type              | Description                                                                                                   |
| ------ | ----------------- | ------------------------------------------------------------------------------------------------------------- |
| page   | int (optional)    | Which page of results you want to fetch. Default is 1                                                         |
| limit  | int (optional)    | The amount of rows you want to fetch. Default: 100, Min: 1, Max: 100                                          |
| sort   | string (optional) | How you want the farms sorted when they are returned. Options are `newest` and `oldest`. Default is `newest`. |
| staker | string            | The WAX address of the staker to get staked farms for.                                                        |

```javascript
// Example

const user = "waxdao";

export const getStakedOnly = async (
  user,
  page = 1,
  limit = 100,
  sort = "newest"
) => {
  for (const api of network.endpoints.tokenfarms) {
    try {
      const res = await axios.post(
        `${api}/staked-only`,
        {
          staker: user,
          page: page,
          limit: limit,
          sort: sort,
          json: true,
        },
        {
          headers: {
            "Access-Control-Allow-Origin": "*",
            "Content-Type": "application/json",
          },
        }
      );

      if (res?.data?.farms) {
        console.log(res.data.farms);
        return res.data.farms;
      }
    } catch (error) {
      console.log(`Failed getting staked only from ${api}. Error: ${error}`);
      return [];
    }
    return [];
  }
};
```


---

# 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://waxdao.gitbook.io/waxdao/products/token-farms/developers/api-documentation.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.
