xtoearn-near-sdk

2.2.2 • Public • Published

xtoearn-near-sdk

npm (scoped) npm bundle size (minified)

X-to-Earn makes it incredibly simple for developers to integrate web3 rewards in their app without having to deploy Smart Contracts or write web3 code.

You can create your own programs and add rewards.

Every time a user does an action on your app, trigger xtoearn-near-sdk to send rewards to user's wallet.

Steps

  • Create an account on xtoearn website

  • Add a rewards program

  • Deposit Near tokens and add rewards

  • Install xtoearn-near-sdk

  • Install dotenv npm package

    #!/bin/bash
    $ npm install xtoearn-near-sdk dotenv
    
  • Create a .env and copy contents from .env.example

  • Pass below parameters

    • Set Method Name to process_events
    • Set Account Id
  • Pass params and Set Contract Id (Visible on xtoearn website)

Single Program

If you want to run just a single program, you could use the below setup:

  • You can pass private key for one Program in the args example: "private_key"="YOUR_KEY"
  • Copy your program private key (function access) from xtoearn website and add to args
  • Trigger xtoearn-near-sdk to give out rewards to user on your platform

Multiple Programs

If you would be using one process to send rewards for all your programs, you could use the below setup:

  • Create a folder and specify the complete path of the folder in the args example: "credentials_dir"="/absolute/path/to/directory/with/keys"
  • Download each program private key from xtoearn website and copy the file to CREDENTIALS_DIR
  • Trigger xtoearn-near-sdk to give out rewards to user on your platform

Usage

import give_rewards from "xtoearn-near-sdk";
import dotenv from 'dotenv';

const args = {
  "reward_name": "video_view", // Event for which you want to reward the user
  "program_name": "program", // Program Name
  "user_wallet": "user-to-reward.near", // The user who you would want to reward
  "program_owner": "yourACCOUNT_ID", // This would be your account id
  // Pass either credentials_dir or private_key
  "credentials_dir": "/absolute/path/to/where/keys/are/stored",
  "private_key": "private-key-of-program" // Private with function access for contract
};

const CONTRACT_ID = "program-yourACCOUNT_ID-x2earn.near" // Can be found on the x2earn dashboard
const ACCOUNT_ID = "yourACCOUNT_ID"


give_rewards(CONTRACT_ID, ACCOUNT_ID, process.env.METHOD_NAME, args, process.env.ATTACHED_DEPOSIT).then(reward => console.log(reward));

Package Sidebar

Install

npm i xtoearn-near-sdk

Weekly Downloads

0

Version

2.2.2

License

ISC

Unpacked Size

9.11 kB

Total Files

6

Last publish

Collaborators

  • vaulstein