import {
ProviderInternalHDWallet,
ThorClient,
VeChainProvider,
VeChainSigner,
} from "@vechain/sdk-network";
import { X2EarnRewardsPool } from "@vechain/vebetterdao-contracts";
const PRIVATE_KEY = ""
const ACCOUNT_ADDRESS_OF_PK = ""
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 wallet = new ProviderInternalBaseWallet(
[
{
privateKey: Buffer.from(
PRIVATE_KEY.slice(2),
'hex',
),
address: ACCOUNT_ADDRESS_OF_PK,
},
],
);
const provider = new VeChainProvider(
thor,
wallet,
false,
);
const signer = await provider.getSigner(
ACCOUNT_ADDRESS_OF_PK,
);
// 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();
}