import { Encryptable } from '@cofhe/sdk';
import { parseAbi } from 'viem';
import { sepolia } from 'viem/chains';
// externalEuint32 is a bytes32 value type on the wire
const encryptedCounterAbi = parseAbi([
'function setCount(bytes32 inCount, bytes inputProof)',
]);
// 1) Encrypt right before sending the transaction
const [countHash, signature] = await cofheClient
.encryptInputs([Encryptable.uint32(42n)])
.setConsumingContract(encryptedCounterAddress)
.execute();
// 2) Pass the handle and its proof
const hash = await walletClient.writeContract({
chain: sepolia,
account,
address: encryptedCounterAddress,
abi: encryptedCounterAbi,
functionName: 'setCount',
args: [countHash, signature],
});
await publicClient.waitForTransactionReceipt({ hash });