Using the xtoearn-near-sdk-js in your app
xtoearn-near-sdk-js reference
Setup the xtoearn-near-sdk-js in your app
Install dotenv npm package
#!/bin/bash
$ npm install xtoearn-near-sdk dotenv
Create a .env and copy contents from .env.example
CONTRACT_ID = NEAR_ENV = NODE_ENV = ACCOUNT_ID = METHOD_NAME = ATTACHED_DEPOSIT = PRIVATE_KEY =
Set METHOD_NAME to
process_events
Set ACCOUNT_ID to your Account ID which you connected to the app
Set CONTRACT_ID to your Contract Name as shown on the xtoearn app
Usage
Single Program
To send Rewards for a single Rewards Program:
Generate and download the Private Key of the Rewards Program
Store the private key in your
.env
as PRIVATE_KEYTo pay out the rewards call the
give_rewards
function with the necessary inputs
import give_rewards from "xtoearn-near-sdk";
import dotenv from 'dotenv';
const args = {
"reward_name": "video_view", // Reward name for the reward that you're paying out
"program_name": "program", // Program Name
"user_wallet": "user-to-reward.near", // The user you're sending rewards to
"program_owner": "yourACCOUNT_ID", // This would be your account i
"private_key": process.env.PRIVATE_KEY// Private with function access for contract
};
const CONTRACT_ID = "program-yourACCOUNT_ID-xtoearn.near" // Can be found on the x2earn dashboard
const ACCOUNT_ID = process.env.ACCOUNT_ID
give_rewards(CONTRACT_ID, ACCOUNT_ID, process.env.METHOD_NAME, args, process.env.ATTACHED_DEPOSIT).then(reward => console.log(reward))
Multiple Programs
To send rewards for multiple Rewards Programs:
Create a directory and set
credentials_dir
in theargs
to the complete path of the directoryDownload each program private key from xtoearn website and copy the file to the directory created above
To pay out the rewards call the
give_rewards
function with the necessary inputs
import give_rewards from "xtoearn-near-sdk";
import dotenv from 'dotenv';
const args = {
"reward_name": "video_view", // Reward name for the reward that you're paying out
"program_name": "program", // Program Name
"user_wallet": "user-to-reward.near", // The user you're sending rewards to
"program_owner": "yourACCOUNT_ID", // This would be your account id
"credentials_dir": "/absolute/path/to/where/keys/are/stored",
const CONTRACT_ID = "program-yourACCOUNT_ID-xtoearn.near" // Can be found on the x2earn dashboard
const ACCOUNT_ID = process.env.ACCOUNT_ID
give_rewards(CONTRACT_ID, ACCOUNT_ID, process.env.METHOD_NAME, args, process.env.ATTACHED_DEPOSIT).then(reward => console.log(reward))
Last updated
Was this helpful?