Creating the contract

Import TFHE library:

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.9 <0.9.0;

import "fhevm/lib/TFHE.sol";
import "fhevm/abstracts/EIP712WithModifier.sol"; 

Defining the ERC20 contract:

Our contract will implement the EIP712WithModifier interface. The EIP-712 signature is necessary for reencrypt, which is used so that each user can only decrypt their own balance.

contract EncryptedERC20 is EIP712WithModifier {
}

State variables:

We want our balances to be encrypted so we define a mapping of the address to an euint32 data type. Initialize state variables for totalSupply, balances, and allowances using encrypted integers (e.g., euint32 for balances)

 euint32 private totalSupply;
 string public constant name = "CUSD";
 uint8 public constant decimals = 18;
 mapping(address ⇒ euint32) balances; 
 mapping(address => mapping(address => euint32)) internal allowances;

Last updated