> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openformat.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Check and Reward Missions

> Checks whether a user has completed all the actions that make up a mission, and if they have, it rewards them with the appropriate XP and badges.

## Use cases

1. **Language Learning Apps:** Reward users with XP and badges for completing levels or reaching streak milestones, granting them access to exclusive levels.
2. **Corporate Training:** Automatically reward employees with certificates or badges after completing required training modules, aiding in progress tracking and compliance.
3. **Music Learning Platforms:** Reward students with badges for completing lessons or practice hours, granting them access to feedback sessions with professional musicians or exclusive performance opportunities.
4. **Gaming Platforms:** Reward players with XP or unlockable content for completing in-game missions or challenges, recognizing achievements and encouraging continued gameplay.
5. **Educational Institutions & Digital CVs:** Reward students for completing both in-person and online education, providing badges that verify their micro-learning achievements.

## Video Setup

<video autoPlay muted controls loop playsInline className="w-full rounded-md" src="https://mintcdn.com/openformat/vGurOUJG2onkcsD3/assets/templates/check-and-reward-missions.mp4?fit=max&auto=format&n=vGurOUJG2onkcsD3&q=85&s=76897a0f5ac774cdb6dcf66f7135ff86" data-path="assets/templates/check-and-reward-missions.mp4" />

## Prerequisites

1. **Setup OPENFORMAT**

   Before you can continue, please complete the following steps to obtain the necessary credentials:

   1. **Go to the [OPENFORMAT Dashboard](https://app.openformat.tech)**
   2. **Register** for an account
   3. **Generate an API Key**
   4. **Create a dApp**
   5. **Create a Badge** (only if required)

## Get Started

A step-by-step breakdown of how this template works.

<Steps>
  <Step title="Remix this template">
    [Clone](https://buildship.app/remix?template=openformat-reward-missions)
    this template in BuildShip.
  </Step>

  <Step title="OPENFORMAT Node Inputs">
    Add your OPENFORMAT `API Key` and `Private Key` into the Check
    missions, Reward XP and Reward Badge node inputs.
  </Step>

  <Step title="Test Integration">
    To test the integration, click on **Test** and add the `dAppId` and `userId` of your user to the body of the request. e.g.

    ```json theme={null}
    {
      "dappId": "0x707ff576432e6d7a438b1beab763d6c41be27207",
      "userId": "0x67c7d1b286926642a91d38265bc2a25ea0045726"
    }
    ```

    <video autoPlay muted loop playsInline className="w-full aspect-video" src="https://mintcdn.com/openformat/vGurOUJG2onkcsD3/images/badge-access-verifier/badge-access-verifier-test.mp4?fit=max&auto=format&n=vGurOUJG2onkcsD3&q=85&s=2de3fe34208c0f234a4ac3b8fd325e8b" data-path="images/badge-access-verifier/badge-access-verifier-test.mp4" />
  </Step>
</Steps>

## Node Inputs

### Check Missions

| Key        | Description                                                                                                                  |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `API Key`  | Your OPENFORMAT API Key. which can be created in the [Dashboard](https://app.openformat.tech/home/settings).                 |
| `dApp ID`  | The ID for your OPENFORMAT dApp, you can create a dApp in the OPENFORMAT [Dashboard](https://app.openformat.tech/home/apps). |
| `User ID`  | The address of the user, which will be their existing web3 account address.                                                  |
| `Missions` | The list of missions to check for.                                                                                           |

### Missions Example

My example app is designed to help users run their first 10km by completing 1km runs.
Each time a user completes a 1km run, we use the [Reward XP](./reward-xp) node to complete the `complete_run` action.
Once they complete the `complete_run` action a specific amount of times, they will complete a mission. We use the following mission configuration:

```json theme={null}
[
  {
    "name": "Complete First Run",
    "requirements": [{ "action_name": "complete_run", "count": 1 }],
    "xp_reward_amount": 100,
    "badge_reward_id": "INSERT_COMPLETE_FIRST_RUN_BADGE_ID"
  },
  {
    "name": "Run 5k",
    "requirements": [{ "action_name": "complete_run", "count": 5 }],
    "xp_reward_amount": 200,
    "badge_reward_id": "INSERT_COMPLETE_5K_RUN_BADGE_ID"
  },
  {
    "name": "Run 10k",
    "requirements": [{ "action_name": "complete_run", "count": 10 }],
    "xp_reward_amount": 1000,
    "badge_reward_id": "INSERT_COMPLETE_10K_RUN_BADGE_ID"
  }
]
```

**In this configuration:**

* **First Mission: `complete_first_run`**

  * **Requirements**: The user must complete their first run (`complete_run` action) once.
  * **Rewards**: Upon completion, the user earns 100 XP and receives a badge identified by `BADGE_ID_FIRST_RUN`.

* **Second Mission: `run_5k`**

  * **Requirements**: The user must complete five runs (`complete_run` action) in total.
  * **Rewards**: Upon completion, the user earns 200 XP and receives a badge identified by `BADGE_ID_RUN_5K`.

* **Third Mission: `run_10k`**

  * **Requirements**: The user must complete ten runs (`complete_run` action) in total.
  * **Rewards**: Upon completion, the user earns 1000 XP and receives a badge identified by `BADGE_ID_RUN_10K`.

### Reward XP

| Key            | Description                                                                                                                            |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `API Key`      | Your OPENFORMAT API Key. You can find this in the Settings page of the [Dashboard](https://app.openformat.tech) (String)               |
| `dApp ID`      | The ID of your OPENFORMAT dApp. You can get this in the [Dashboard](https://app.openformat.tech) (String, max 32 characters)           |
| `Private Key`  | The Private Key of your web3 account. You can find this in the Settings page of the [Dashboard](https://app.openformat.tech).          |
| `Action ID`    | A random identifier for the action that has been completed, e.g., `completed_workout`, `completed_lesson`. (String, max 32 characters) |
| `Amount of XP` | The amount of XP to be rewarded. (Number, whole number only)                                                                           |
| `Receiver`     | The address of the receiver, which will be the existing web3 account or the newly generated account.                                   |
| `Await`        | Wait for the transaction to be confirmed on the blockchain. (Boolean, default: true)                                                   |

### Reward Badge

| Key           | Description                                                                                                                                                                          |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `API Key`     | Your OPENFORMAT API Key. You can find this in the Settings page of the [Dashboard](https://app.openformat.tech) (String)                                                             |
| `dApp ID`     | The ID of your OPENFORMAT dApp. You can get this in the [Dashboard](https://app.openformat.tech) (String, max 32 characters)                                                         |
| `Private Key` | The Private Key of your web3 account. You can find this in the Settings page of the [Dashboard](https://app.openformat.tech).                                                        |
| `Badge Name`  | The name of the badge that you are awarding, this must exactly match the name of the badge created. You can create a badge in the [Dashboard](https://app.openformat.tech). (string) |
| `Receiver`    | The address of the receiver, which will be the existing web3 account or the newly generated account.                                                                                 |
| `Await`       | Wait for the transaction to be confirmed on the blockchain. (Boolean, default: true)                                                                                                 |

## Gotchas and Troubleshooting

* If you encounter issues, ensure all required fields are correctly filled and check your API and Private Key configurations in the Dashboard settings.
* For custom name and image configurations for anonymous users, edit the `Improve Leaderboard` node with your preferred text and URLs.
