mirror of
https://github.com/luxfhe/example-smart-wallet.git
synced 2026-10-30 18:13:16 +00:00
- @luxfhe/wasm: ^0.2.0 - @luxfhe/kms: ^0.2.0 - @luxfhe/relayer-sdk: ^0.6.0 - @luxfhe/mock-contracts: ^0.6.0 - Remove deprecated Zama dependencies
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { Counter } from "../typechain-types";
|
|
import { task } from "hardhat/config";
|
|
import type { TaskArguments } from "hardhat/types";
|
|
|
|
task("task:addCount")
|
|
.addParam("amount", "Amount to add to the counter (plaintext number)", "1")
|
|
.setAction(async function (taskArguments: TaskArguments, hre) {
|
|
const { luxfhe, ethers, deployments } = hre;
|
|
const [signer] = await ethers.getSigners();
|
|
|
|
if ((await ethers.provider.getBalance(signer.address)).toString() === "0") {
|
|
await luxfhe.getFunds(signer.address);
|
|
}
|
|
|
|
const amountToAdd = Number(taskArguments.amount);
|
|
const Counter = await deployments.get("Counter");
|
|
|
|
console.log(`Running addCount(${amountToAdd}), targeting contract at: ${Counter.address}`);
|
|
|
|
const contract = await ethers.getContractAt("Counter", Counter.address);
|
|
|
|
const encryptedAmount = await luxfhe.encrypt_uint32(amountToAdd);
|
|
|
|
const contractWithSigner = contract.connect(signer) as unknown as Counter;
|
|
|
|
try {
|
|
// add() gets `bytes calldata encryptedValue`
|
|
// therefore we need to pass in the `data` property
|
|
await contractWithSigner.add(encryptedAmount);
|
|
} catch (e) {
|
|
console.log(`Failed to send add transaction: ${e}`);
|
|
return;
|
|
}
|
|
});
|