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

# XP Rewards Integration

> Reward your existing users with on-chain experience points (XP). This template handles the process of issuing XP directly to users based on their unique identifier, making it easy to integrate gamification into your existing application.

## Use cases

1. **Loyalty Program** - Reward users for their continued engagement and loyalty. Users earn experience points (XP) for actions such as logging in daily, making purchases, or referring friends.
2. **Achievement System** - Implement an achievement system where users earn XP for completing specific milestones or challenges within your application.
3. **Event Participation** - Award XP to users for participating in special events, contests, or promotions.

## Video Setup

<iframe width="100%" height="500" src="https://www.loom.com/embed/2b7ffa1a03fc43af9634f729a3631a77?sid=95368d15-4b64-4e61-a36f-d636118353de" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen />

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

2. **Supabase Table**

Create a Supabase table for storing generated web3 accounts for a given `user_id`. Follow the table structure below. You will need to add the following columns: `account_address`, `private_key` and `user_id`.

<Warning>
  Disable Row Level Security (RLS) for testing purposes only. We
  highly recommend enabling RLS in any production environment to
  ensure data security and integrity.
</Warning>

<img src="https://mintcdn.com/openformat/vGurOUJG2onkcsD3/images/reward-user-xp/new-table.png?fit=max&auto=format&n=vGurOUJG2onkcsD3&q=85&s=b761acf0a60c427f977f194fd2baf538" alt="New Table" width="996" height="1404" data-path="images/reward-user-xp/new-table.png" />

## Get Started

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

  <Step title="Supabase Node Inputs">
    Add your Supabase `API Key` and `API URL` to the Get Row and
    Create Row node inputs.
  </Step>

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

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

    ```json theme={null}
    {
      "user_id": "56ba8d26-1137-42a1-a5a8-88066b583f56"
    }
    ```

    <video autoPlay muted loop playsInline className="w-full aspect-video" src="https://mintcdn.com/openformat/vGurOUJG2onkcsD3/images/reward-user-xp/reward-xp-test.mp4?fit=max&auto=format&n=vGurOUJG2onkcsD3&q=85&s=5dadd2ff0da334e015ba3311501d2ffd" data-path="images/reward-user-xp/reward-xp-test.mp4" />
  </Step>

  <Step title="Generate a Leaderboard">
    Now that you've rewarded XP to a user, you can generate a leaderboard using the [Leaderboard Template](./leaderboard).
  </Step>
</Steps>

## Node Inputs

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