VeBetterDAO Docs
  • VeBetterDAO
    • VeBetterDAO
    • B3TR & VOT3 Tokens
    • B3TR Emissions
    • Treasury
    • X2Earn Allocations
    • X2Earn Apps
    • Governance
    • Voter Rewards
    • Smart Contracts
    • Roles And Permissions
    • Trust Assumptions
    • Verify contract
  • Developer Guides
    • Get Started
    • Test Environment
    • Testnet B3TR tokens
    • Reward Distribution
      • JavaScript
      • Solidity
      • Manage distributors funds
    • Sustainability Proof and Impacts
    • Reward Metadata
    • Security Considerations
    • Submit Your App
    • X2Earn Creators NFT
    • Resources
  • VePassport
    • VePassport
    • Checks
      • Personhood Check
      • Proof of Participation
      • Proof of investment
      • Bot Signaling
      • Blacklisting and Whitelisting
    • Passport Delegation
    • Accounts Linking
    • Roles
  • Vechain Node Holders Guides
    • Endorsement Guide for VeChain Node Holders
    • Node Management
    • Vechain Nodes X GM NFTs: Maximizing Benefits within VeBetter DAO
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Developer Guides
  2. Reward Distribution

Solidity

In this example, we assume that you are building a smart contract where users can submit some sustainable action that is being approved/rejected by some moderator. If the action is approved the user can claim his rewards. No backend is involved.

Your contract should look like this:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

// can find here: https://github.com/vechain/vebetterdao-contracts/tree/main/contracts/interfaces
import "./interfaces/IX2EarnRewardsPool.sol";

/**
 * Example contract with key functionality to interact with the x2Earn rewards pool
 * and distribute rewards.
 * You can customize this contract in the way 
 */
contract MySustainableAppContract {
    IX2EarnRewardsPool public x2EarnRewardsPool;
    bytes32 public VBD_APP_ID;
    
    // a dummy mapping pretending you have a way to track and 
    // validate user actions on chain.
    mapping(uint256 actionId => ActionStruct) public sustainableActions;
    mapping(uint256 actionId => bool) public rewardsClaimed;
    
    // You will need to setup the address of the X2EarnRewardsPool contract
    // and your APP_ID on VeBetterDAO
    constructor(IX2EarnRewardsPool _x2EarnRewardsPool, bytes32 _VBD_APP_ID) {
        x2EarnRewardsPool = _x2EarnRewardsPool;
        VBD_APP_ID = _VBD_APP_ID;
    }

    /**
     * @notice A function that allows a user to claim a reward for a specific
     * sustainable action that they performed.
     * 
     * IMPORTANT: the address of this contract must be set as a distributor 
     * of your APP in order to move funds from the X2EarnRewardsPool contract. 
     * You can set this on the VeBetterDAO governance app.
     */
    function claimReward(uint256 _actionId) external {
        // ... some code to check if the action is valid and user can claim

        // If distributeReward fails, it will revert
        x2EarnRewardsPool.distributeReward(
            VBD_APP_ID,
            actions[_actionId].rewardAmount,
            msg.sender, // this is the user calling the claimReward function
            "" // proof and impacts not provided
        );

        rewardClaimed[_actionId] = true;

        emit RewardClaimed(_actionId, msg.sender);
    }
}

The address of this contract must be set as a distributor of your APP in order to move funds from the X2EarnRewardsPool contract.

You can set this on the VeBetterDAO governance app.

Sustainability Proof

To be able to distribute the rewards you will need to add the PUBLIC ADDRESS of the wallet calling the distributeRewards function as a Reward Distributor of your app. To do so, you need to:

1) Connect with your app's admin wallet to the governance dapp

2) Go to your app's page

3) Click the cogs button to enter the settings page

4) Scroll down to the "Reward Distributors" section, and add the public address as a reward distributor

5) Save changes

PreviousJavaScriptNextManage distributors funds

Last updated 7 days ago

Was this helpful?

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

Sustainability Proofs and Impacts