Send 3rd Party Rewards Data
If you have an app, you can setup custom Everyday Rewards for your users so that they can earn Moxie rewards by using your app based on their respective usages. If you want to enable this in your app/project, you can contact Alex for discussion.
In order to distribute the rewards, it is required for you to track user's usage on your app and send it to us.
In this tutorial, you will learn, as a vendor, how to use the Webhook 3rd Party Rewards REST API to fetch the clearing price of a certain auction in Node.js.
Pre-requisites
Before following the tutorial, make sure that your machine fulfills the following requirements:
- Install dependency
node-fetch
to your project:
- npm
- yarn
- pnpm
- bun
npm install node-fetch
yarn add node-fetch
pnpm add node-fetch
bun install graphql node-fetch
- Your will need a Partner ID & a special API key to access to the Webhook 3rd Party Rewards REST API. This will be given to you once you're onboarded as a vendor.
Step 1: Add REST API Call To The Code
You can easily call the Webhook 3rd Party Rewards REST API by sending a POST request providing the partnerId
assigned to you and add the event usage details to the request body by the following code snippet with node-fetch
:
There are several rules to follow for the input value in the request body to be considered valid for processing:
- The
id
must be unique value for each call.id
value used in previous API call can't be used in subsequent calls. data
field must have AT LEAST 1 object and cannot be an empty array as there will be no rewards to be distributed.- For
CHANNEL
andNETWORK
type, the inputtedentityId
must have their corresponding Fan Tokens deployed. If not, the API call will revert.
- TypeScript
- JavaScript
import fetch from "node-fetch";
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <YOUR_AIRSTACK_API_KEY>",
},
body: JSON.stringify({
// unique ID, e.g. UUID
id: "1",
// the current timestamp
timestamp: "2024-09-11T04:04:51.901Z",
data: [
{
/*
* Enter different value depending on the entityType:
* - For `CHANNEL` -> input the Channel ID
* - For `USER` -> input the user's FID
* - For `NETWORK` -> currently only network:farcaster
*/
entityId: "3",
// CHANNEL, USER, NETWORK
entityType: "USER",
// Amount of Moxie to be distributed in wei
amount: "1000000",
},
// Other distribution
],
}),
};
// The Partner ID assigned for each vendor
const partnerId = "YOUR_PARTNER_ID";
fetch(`https://rewards.moxie.xyz/partners/${partnerId}/events`, options)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));
const fetch = require("node-fetch");
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <YOUR_AIRSTACK_API_KEY>",
},
body: JSON.stringify({
// unique ID, e.g. UUID
id: "1",
// the current timestamp
timestamp: "2024-09-11T04:04:51.901Z",
data: [
{
/*
* Enter different value depending on the entityType:
* - For `CHANNEL` -> input the Channel ID
* - For `USER` -> input the user's FID
* - For `NETWORK` -> currently only network:farcaster
*/
entityId: "3",
// CHANNEL, USER, NETWORK
entityType: "USER",
// Amount of Moxie to be distributed in wei
amount: "1000000",
},
// Other distribution
],
}),
};
// The Partner ID assigned for each vendor
const partnerId = "YOUR_PARTNER_ID";
fetch(`https://rewards.moxie.xyz/partners/${partnerId}/events`, options)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));
It is important to keep in mind that the Moxie distribution for each entityType
will be different:
- For
USER
type,- If the user has no Fan Token, then 100% will go straight to the user and their rewards will be claimable as a regular Everyday Rewards.
- Otherwise, their rewards will be split based on the % allocated for their Fans
- e.g. if the Fan Token is configured to split 90% with fans, then 90% of the rewards go to the Fans through buy & burn process, while the rest 10% go to the user for claim.
- For
CHANNEL
andNETWORK
type, 100% of the rewards will be distributed through regular buy & burn and holders will benefit from the price increase.
Step 2: Execute Your Code
Once you have your code ready, you can execute it by running the following command:
- TypeScript
- JavaScript
ts-node index.ts
node index.js
If it runs successfully, you should see the data returned in the terminal:
{
"requestId": "62a6ed27-61de-446e-b222-0f09dd60bb8a",
"success": true
}
If success
is true
, you have successfully sent your usage data to Moxie for processing. For your users, they should be able to claim their rewards in the Frames as part of the Everyday Rewards.
Congrats! 🥳🎉 You've just successfully sent 3rd party rewards data to Moxie!
Developer Support
If you have any questions or need help with other use cases, feel free to join the /airstack Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.