create_reward
Create redeemable rewards for loyalty programs by defining token costs, names, and descriptions to incentivize customer engagement.
Instructions
Create a new reward redeemable with loyalty tokens
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token_address | Yes | Token contract address | |
| name | Yes | Reward name | |
| description | No | Reward description | |
| cost | Yes | Token cost to redeem |
Implementation Reference
- Implementation of the 'create_reward' MCP tool which validates authorization, verifies the loyalty program ownership, and inserts the new reward into the database.
mcpServer.tool("create_reward", { description: "Create a new reward redeemable with loyalty tokens", inputSchema: { type: "object" as const, properties: { token_address: { type: "string", description: "Token contract address" }, name: { type: "string", description: "Reward name" }, description: { type: "string", description: "Reward description" }, cost: { type: "number", description: "Token cost to redeem" } }, required: ["token_address", "name", "cost"] }, handler: async ({ token_address, name, description, cost }: any) => { const err = authGuard(["manage_rewards"]); if (err) return T(err); const d = db(); const { data: prog } = await d.from("loyalty_programs").select("id").eq("token_address", token_address.toLowerCase()).eq("merchant_address", agent.ownerAddress).single(); if (!prog) return T('{"error":"Program not found or not owned by you"}'); const { data: reward, error } = await d.from("rewards").insert({ name: name.trim(), description: description?.trim() || null, cost, token_address: token_address.toLowerCase(), merchant_address: agent.ownerAddress, is_active: true }).select("id,name,description,cost,is_active,created_at").single(); if (error) return T(JSON.stringify({ error: error.message })); return T(JSON.stringify({ reward, message: "Reward created" })); }, });