mirror of
https://github.com/luxfhe/example-confidential-voting.git
synced 2026-10-30 18:13:35 +00:00
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { task } from "hardhat/config";
|
|
import type { ArgumentType, TaskArguments } from "hardhat/types";
|
|
|
|
import { createFheInstance } from "../utils/instance";
|
|
|
|
task("task:vote")
|
|
.addParam("option", "Option to choose")
|
|
.addParam("account", "Specify which account [0, 9]")
|
|
.setAction(async function (taskArguments: TaskArguments, hre) {
|
|
const { ethers, deployments } = hre;
|
|
|
|
const Voting = await deployments.get("Voting");
|
|
|
|
const signers = await ethers.getSigners();
|
|
|
|
const voting = await ethers.getContractAt("Voting", Voting.address);
|
|
|
|
console.log(`contract at: ${Voting.address}, for signer: ${signers[taskArguments.account].address}`);
|
|
|
|
const { instance } = await createFheInstance(Voting.address, hre);
|
|
const eOption = await instance.encrypt_uint8(Number(taskArguments.option));
|
|
|
|
const tx = await voting.connect(signers[Number(taskArguments.account)]).vote(eOption);
|
|
const receipt = await tx.wait();
|
|
console.log(`Voted for option ${taskArguments.option}!`);
|
|
console.log(`Result: ${JSON.stringify(receipt)}`);
|
|
});
|