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 previous section).
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:
Explore the full range of fhEVM capabilities in the Smart Contract section.
Use the fhevm-contracts
library and extend from the basic contract templates.
The fhevm-contracts is a Solidity library designed for developers to easily develop confidential smart contracts using fhEVM. It provides:
Ready-to-use confidential contracts: Pre-built implementations of common token standards with FHE capabilities
Base contracts: Foundational building blocks for creating custom confidential smart contracts
Extensions: Additional features and utilities that can be added to base contracts
Testing utilities: Tools to help test FHE-enabled smart contracts
See more details in the fhEVM-contracts documentation.
Your contract is ready! Let's move on to testing and deployment.