JavaScript

Setup a lambda function or an endpoint that will send the B3TR tokens to the user, providing also a proof and impacts of the rewarding action.

We will use @vechain/sdk-network and @vechain/vebetterdao-contracts to interact with VeBetterDAO's X2EarnRewardsPool contract to distribute the rewards.

Run the following command to install the packages:

yarn add @vechain/sdk-network @vechain/vebetterdao-contracts

To distribute the rewards you will need 2 information:

  • Node URL

TESTNET: https://testnet.vechain.org
MAINNET: https://mainnet.vechain.org
  • Your APP_ID on VeBetterDAO: create app here to obtain the APP_ID.

Now you can distribute the reward like this:

import {
  ProviderInternalHDWallet,
  ThorClient,
  VeChainProvider,
  VeChainSigner,
} from "@vechain/sdk-network";
import { X2EarnRewardsPool } from "@vechain/vebetterdao-contracts";

function rewardUser() {
    // To transfer B3TR we first need to connect to the blockchain with
    // a wallet capable of signing and broadcastisting transactions
    const thor = ThorClient.at(process.env.NODE_URL || "");
    const provider = new VeChainProvider(
      thor,
      new ProviderInternalHDWallet(
        process.env.REWARD_SENDER_MNEMONIC?.split(" ") || []
      )
    );
    const rootSigner = await provider.getSigner();

    // Call the VeBetterDAO smart contract
    const x2EarnRewardsPoolContract = thor.contracts.load(
      process.env.X2EARN_REWARDS_POOL_ADDRESS || "",
      X2EarnRewardsPool.abi,
      rootSigner as VeChainSigner
    );
    
    const tx =
      await x2EarnRewardsPoolContract.transact.distributeRewardDeprecated(
        process.env.VEBETTERDAO_APP_ID || "",
        10,
        address,
        JSON.stringify({
          version: 2,
          description: "User refilled water from a sustainable source",
          proof: {
            image: "https://image.png",
            link: "https://twitter.com/tweet/1",
          },
          impact: {
             carbon: 100,
             water: 200
          }
        })
      );

    await tx.wait();
}

Sustainability Proof

Read more about the proof standard and how we expect you to provide it in the Sustainability Proofs and Impacts section.

Last updated

Was this helpful?