Deploying rewards using the SDK
This page provides an example of setting up and deploying the incentives for an offer.
This guide walks through the complete process of launching an offer with a constant reward. A new offer consist of 3 main steps:
Creating the offer with the requirements and metadata
Adding a distributor to the offer with the rewards
Deploying the distributor to activate the offer and allow users to start claiming the rewards
Prerequisites
Before you begin, make sure you have:
Access to a Solana wallet with private key
An RPC URL for Solana network connections
The Torque SDK installed in your project
Setting Up the SDK Connection
First, initialize the SDK with your private key and RPC URL. Then call the authenticate function to authorize your SDK instance.
const signer = Keypair.fromSecretKey(<WALLET PRIVATE KEY>);
const sdk = new TorqueSDK({
apiUrl: "https://server.torque.so",
rpcUrl: "<RPC URL>",
});
const token = await sdk.authenticate(signer);In this setup:
<WALLET PRIVATE KEY>: Your Solana wallet's private key<RPC URL>: Your Solana RPC endpoint URLsigner: Your Keypair for authenticating with Torque
Creating an Offer
An offer defines the conditions users must meet to receive rewards.
The example below creates an offer with a BUY requirement, which requires users to purchase a specific token. In this step, you also define the metadata and the time frame for the offer.
const offer = await sdk.offers.createOffer({
startTime: new Date(),
endTime: new Date(new Date().setMonth(new Date().getMonth() + 1)),
metadata: {
title: "<REQUIRED TITLE>",
image: "<REQUIRED IMAGE URL>",
description: "<DESCRIPTION HERE>"
},
requirements: [
{
type: "BUY",
config: {
tokenAddress: {
type: "string",
validation: "exactMatch",
value: "<REQUIRED TOKEN ADDRESS>",
},
amount: {
type: "number",
min: "<REQUIRED MINIMUM AMOUNT>",
},
},
oracle: "SOLANA_TX",
},
],
});Key Components:
Requirements: Conditions users must meet to qualify
type: "BUY": Requires users to purchase a specific tokentokenAddress: The Solana address of the required tokenamount: Minimum token amount users must purchaseoracle: "SOLANA_TX": Uses Solana transactions to verify requirements
Time Frame:
startTime: When the offer becomes active (set to now in this example)endTime: When the offer expires (set to one month from now)
Metadata:
title: Display title for your offerimage: URL to an image representing your offerdescription: Description of your offer
After successful creation, offerResult will contain the offer's unique ID and other details you'll need for subsequent steps.
Adding a Distributor
Distributors determine how rewards are allocated to users. The following example creates a distributor with a constant reward of 0.01 SOL for each user that meets the offer requirements. The total amount is the amount of SOL that will be allocated for the offer.
const distributor = await sdk.offers.addDistributo(offer.id, {
{
type: "CONVERSION",
crankGuard: {
recipient: "USER",
activation: {
type: "OFFER_START",
},
distributionFunctionInput: {
type: "CONVERSION_INDEX",
},
},
distributionFunction: {
type: "CONSTANT",
yIntercept: 0.01,
},
emissionType: "SOL",
totalFundAmount: 1,
}
})Distributor Configuration Explained:
Type:
"CONVERSION"- Rewards users when they complete the requirementCrank Guard:
recipient: "USER": Rewards go directly to usersactivation: { type: "OFFER_START" }: Begins distribution when offer startsdistributionFunctionInput: { type: "CONVERSION_INDEX" }: Uses conversion order index to determine reward amount. Since this is a constant reward, every user will receive the same amount. In case of a dynamic reward, the index would be used to calculate the reward amount for each user.
Distribution Function:
type: "CONSTANT": Uses a constant reward amountyIntercept: 0.01: Sets the reward at 0.01 units
Reward Details:
emissionType: "SOL": Rewards are in SOLtotalFundAmount: 1: Total of 1 SOL allocated for rewards
This configuration creates a distributor that rewards users with 0.01 SOL each time they meet the offer requirements, up to a total of 1 SOL across all users. In this example, there will be a total of 100 users that will be able to receive the reward (1 SOL / 0.01 SOL = 100)
Deploying the Distributor
To activate a distributor, it first needs to be deployed. This createst an escrow account with the total funding amount to distribute rewards according to your specifications.
const deploy = await torque.offers.deployDistributor(offer.id, distributor.id)Viewing Your Offer
Once deployed, users can view your offer at:
https://platform.torque.so/offer/{{offerId}}Replace {{offerId}} with the offer ID received from offer.id.
Best Practices
Test First: Consider testing with small reward amounts
Monitor: Keep an eye on your offer's performance through the Torque dashboard
Fund Adequately: Ensure your wallet has sufficient funds for the total reward amount
Set Clear Conditions: Make offer requirements clear to users
Last updated
