2. Writing contracts
Last updated
Was this helpful?
Last updated
Was this helpful?
This document explains how to write confidential smart contract using fhEVM in Hardhat projects.
Before proceeding, ensure you have:
A working Hardhat environment set up (see ).
Basic knowledge of Solidity.
An understanding of ERC20 tokens.
The Hardhat template includes an example contract in the contracts/
folder - MyConfidentialERC20.sol
. This contract enables:
Private ERC20 token transfers.
Encrypted balances.
Minting functionality for authorized addresses.
Let's break down the contract.
TFHE.sol
: The core Solidity library of Zama's fhEVM. It enables encrypted data type like euint64
, secures encrypted operations, such as addition and comparison and allows access control.
SepoliaZamaFHEVMConfig
: A configuration contract that automatically sets up the required configurations for real-time encrypted operations on the Sepolia testnet.
ConfidentialERC20Mintable.sol
: The confidential smart contract that allows for full ERC20 compatibility with FHE encryption.
This contract inherits SepoliaZamaFHEVMConfig
and ConfidentialERC20Mintable
.
The constructor initializes the ERC20 token with a name and symbol, setting the deployer as the initial owner.
This is a simple basic contract that we will deploy and use in this tutorial. To write more complex confidential smart contracts or customize your own functions:
Use the fhevm-contracts
library and extend from the basic contract templates.
Your contract is ready! Let's move on to testing and deployment.
Explore the full range of fhEVM capabilities in the section.
See more details in .