3. SWITCH TO FHEVM

3.1 create FHECounter.sol

cd fhevm-counter-demo/contracts
nano FHECounter.sol

coppy this :

// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { FHE, euint32, externalEuint32 } from "@fhevm/solidity/lib/FHE.sol";
import { EthereumConfig } from "@fhevm/solidity/config/ZamaConfig.sol";

/// @title A simple FHE counter contract
contract FHECounter is EthereumConfig {
  euint32 private _count;

  function getCount() external view returns (euint32) {
    return _count;
  }

  function increment(externalEuint32 input, bytes calldata proof) external {
    euint32 value = FHE.fromExternal(input, proof);
    _count = FHE.add(_count, value);
    FHE.allowThis(_count);
    FHE.allow(_count, msg.sender);
  }

  function decrement(externalEuint32 input, bytes calldata proof) external {
    euint32 value = FHE.fromExternal(input, proof);
    _count = FHE.sub(_count, value);
    FHE.allowThis(_count);
    FHE.allow(_count, msg.sender);
  }
}

3.2 .compile

cd ..
npx hardhat compile

out put :

Compiled 2 Solidity files successfully

Last updated