VeBetter: Build X2Earn Apps
Integration (JavaScript)
Use the VeBetter JavaScript SDK to securely send B3TR rewards with verifiable proofs and metadata from your backend or smart contract.
Prerequisites
JavaScript Version: Distribute B3TR
JavaScript (Backend) is ideal for mobile or web apps with centralized components. It allows you to verify proofs server-side, such as checking timestamps, validating GPS locations, or scoring input data, before triggering onchain distribution.
import { ProviderInternalHDWallet, ThorClient, VeChainProvider } from "@vechain/sdk-network"; import { X2EarnRewardsPool } from "@vechain/vebetterdao-contracts"; import dotenv from 'dotenv'; dotenv.config(); const thor = ThorClient.at('https://testnet.vechain.org'); const provider = new VeChainProvider( thor, new ProviderInternalHDWallet(process.env.MNEMONIC?.split(" ")) ); const signer = await provider.getSigner(); const x2EarnRewardsPoolContract = thor.contracts.load( X2EarnRewardsPool.address.testnet, X2EarnRewardsPool.abi, signer ); const tx = await x2EarnRewardsPoolContract.transact.distributeRewardWithProof( process.env.VEBETTERDAO_APP_ID, rewardAmount, // set the reward amount account, // user's wallet address proofTypes, // e.g. ['image', 'link'] proofValues, // e.g. ['https://...', 'https://...'] impactCodes, // e.g. ['waste_mass'] impactValues, // e.g. [100] description // e.g. "User recycled 1kg of plastic" ); await tx.wait();
import { ProviderInternalHDWallet, ThorClient, VeChainProvider } from "@vechain/sdk-network"; import { X2EarnRewardsPool } from "@vechain/vebetterdao-contracts"; import dotenv from 'dotenv'; dotenv.config(); const thor = ThorClient.at('https://testnet.vechain.org'); const provider = new VeChainProvider( thor, new ProviderInternalHDWallet(process.env.MNEMONIC?.split(" ")) ); const signer = await provider.getSigner(); const x2EarnRewardsPoolContract = thor.contracts.load( X2EarnRewardsPool.address.testnet, X2EarnRewardsPool.abi, signer ); const tx = await x2EarnRewardsPoolContract.transact.distributeRewardWithProof( process.env.VEBETTERDAO_APP_ID, rewardAmount, // set the reward amount account, // user's wallet address proofTypes, // e.g. ['image', 'link'] proofValues, // e.g. ['https://...', 'https://...'] impactCodes, // e.g. ['waste_mass'] impactValues, // e.g. [100] description // e.g. "User recycled 1kg of plastic" ); await tx.wait();
import { ProviderInternalHDWallet, ThorClient, VeChainProvider } from "@vechain/sdk-network"; import { X2EarnRewardsPool } from "@vechain/vebetterdao-contracts"; import dotenv from 'dotenv'; dotenv.config(); const thor = ThorClient.at('https://testnet.vechain.org'); const provider = new VeChainProvider( thor, new ProviderInternalHDWallet(process.env.MNEMONIC?.split(" ")) ); const signer = await provider.getSigner(); const x2EarnRewardsPoolContract = thor.contracts.load( X2EarnRewardsPool.address.testnet, X2EarnRewardsPool.abi, signer ); const tx = await x2EarnRewardsPoolContract.transact.distributeRewardWithProof( process.env.VEBETTERDAO_APP_ID, rewardAmount, // set the reward amount account, // user's wallet address proofTypes, // e.g. ['image', 'link'] proofValues, // e.g. ['https://...', 'https://...'] impactCodes, // e.g. ['waste_mass'] impactValues, // e.g. [100] description // e.g. "User recycled 1kg of plastic" ); await tx.wait();
Your .env file should contain:
MNEMONIC=your twelve word phrase VEBETTERDAO_APP_ID=your registered app ID
MNEMONIC=your twelve word phrase VEBETTERDAO_APP_ID=your registered app ID
MNEMONIC=your twelve word phrase VEBETTERDAO_APP_ID=your registered app ID
You can check the transaction onchain via: https://explore-testnet.vechain.org/
Join our Telegram