# Build An API

We have a public API that you can use, details are in the API Documentation section.

{% content-ref url="/pages/gzORHxUE3AnDEgJxSJHp" %}
[API Documentation](/waxdao/products/token-farms/developers/api-documentation.md)
{% endcontent-ref %}

If you prefer to build your own API instead, you'll need to keep track of data related to the `tf.waxdao` contract. We've made that quite simple for you.

If you're using a SHIP reader, you can watch for the following actions.

### createfarm

This will notify you of the creation of any new farms so you can add them into a table.

| Param             | Type             | Description                                                                                                                                                                                                                         |
| ----------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| creator           | name             | The WAX address of the user who created the farm                                                                                                                                                                                    |
| farm\_name        | name             | The name of the farm they created                                                                                                                                                                                                   |
| staking\_token    | extended\_symbol | The symbol and contract of the token that will be staked in the farm                                                                                                                                                                |
| vesting\_time     | uint64\_t        | The amount of seconds that users will need to lock their tokens for if they stake in the farm                                                                                                                                       |
| original\_creator | name             | Since our partners act as intermediaries, the partners are the `creator` of all their farms. `original_creator` allows them to specify the user who actually created the farm, so we can track it off chain and use it for indexing |

### logclaim

When a user claims rewards, this action will be called so you can track the amounts claimed.

| Param            | Type                     | Description                                                                              |
| ---------------- | ------------------------ | ---------------------------------------------------------------------------------------- |
| user             | name                     | The wallet address of the user who made the claim                                        |
| farm\_name       | name                     | The name of the farm they claimed from                                                   |
| claimed\_rewards | vector\<extended\_asset> | A list of the token amounts that were claimed. Including the amount, symbol and contract |

### logrewards

Whenever the state of a reward pool for a farm changes, this action will log a list of all reward pools for that farm, and their current state.

| Param | Type                    | Description                                                          |
| ----- | ----------------------- | -------------------------------------------------------------------- |
| f     | farm\_struct            | A custom struct which has the same structure as the farms table      |
| rs    | vector\<reward\_struct> | A vector of custom structs which match the rows of the rewards table |

The struct definitions are outlined below.

```cpp
struct farm_struct {
    eosio::name             farm_name;
    eosio::name             creator;
    uint64_t                time_created;
    eosio::extended_symbol  staking_token;
    uint8_t                 incentive_count;
    uint64_t                total_staked;
    uint64_t                vesting_time;
    uint64_t                last_update_time;

    farm_struct(const farms& f)
        : farm_name(f.farm_name),
          creator(f.creator),
          time_created(f.time_created),
          staking_token(f.staking_token),
          incentive_count(f.incentive_count),
          total_staked(f.total_staked),
          vesting_time(f.vesting_time),
          last_update_time(f.last_update_time) {}

    farm_struct() = default;

    // Custom serialization is necessary to pack/unpack the farm_struct when passing
    // to certain actions, such as `logrewards`
    template<typename DataStream>
    friend DataStream& operator << (DataStream& ds, const farm_struct& obj) {
        ds << obj.farm_name
           << obj.creator
           << obj.time_created
           << obj.staking_token
           << obj.incentive_count
           << obj.total_staked
           << obj.vesting_time
           << obj.last_update_time;
        return ds;
    }

    template<typename DataStream>
    friend DataStream& operator >> (DataStream& ds, farm_struct& obj) {
        ds >> obj.farm_name
           >> obj.creator
           >> obj.time_created
           >> obj.staking_token
           >> obj.incentive_count
           >> obj.total_staked
           >> obj.vesting_time
           >> obj.last_update_time;
        return ds;
    }
};

struct reward_struct {
    uint64_t                    id;
    uint64_t                    period_start;
    uint64_t                    period_finish;
    uint128_t                   reward_rate;
    uint64_t                    rewards_duration;
    uint128_t                   reward_per_token_stored;
    eosio::extended_asset       reward_pool;
    eosio::asset                total_rewards_paid_out;

    reward_struct(const rewards& r)
        : id(r.id),
          period_start(r.period_start),
          period_finish(r.period_finish),
          reward_rate(r.reward_rate),
          rewards_duration(r.rewards_duration),
          reward_per_token_stored(r.reward_per_token_stored),
          reward_pool(r.reward_pool),
          total_rewards_paid_out(r.total_rewards_paid_out) {}

    reward_struct() = default;

    // Custom serialization is necessary to pack/unpack the reward_struct when passing
    // to certain actions, such as `logrewards`
    template<typename DataStream>
    friend DataStream& operator << (DataStream& ds, const reward_struct& obj) {
        ds << obj.id
           << obj.period_start
           << obj.period_finish
           << obj.reward_rate
           << obj.rewards_duration
           << obj.reward_per_token_stored
           << obj.reward_pool
           << obj.total_rewards_paid_out;
        return ds;
    }

    template<typename DataStream>
    friend DataStream& operator >> (DataStream& ds, reward_struct& obj) {
        ds >> obj.id
           >> obj.period_start
           >> obj.period_finish
           >> obj.reward_rate
           >> obj.rewards_duration
           >> obj.reward_per_token_stored
           >> obj.reward_pool
           >> obj.total_rewards_paid_out;
        return ds;
    }
};
```

### logstake

Any time a user stakes new tokens into a farm, this action logs the relevant information.

| Param            | Type            | Description                                                         |
| ---------------- | --------------- | ------------------------------------------------------------------- |
| user             | name            | The name of the user who staked                                     |
| farm\_name       | name            | The name of the farm they staked into                               |
| amount           | extended\_asset | The amount that they staked in this transaction                     |
| updated\_balance | extended\_asset | Their current staked balance after adding the new stake to the farm |

### logunstake

Works the same as the logstake action, except this is for unstaking instead.

| Param            | Type            | Description                                  |
| ---------------- | --------------- | -------------------------------------------- |
| user             | name            | The name of the user who unstaked            |
| farm\_name       | name            | The farm that they unstaked from             |
| amount           | extended\_asset | The amount that they unstaked                |
| updated\_balance | extended\_asset | Their current staked balance after unstaking |


---

# 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/build-an-api.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.
