fhEVM
WebsiteLibrariesProduct & ServicesDevelopersSupport
0.6
0.6
  • Welcome to fhEVM
  • White paper
  • Getting Started
    • Overview
    • Quick Start
      • Remix
        • 1. Setting up Remix
        • 2. Connect your wallet to Remix
        • 3. Deploying ConfidentialERC20
        • 4. Interacting with the contract
      • Hardhat
        • Prerequisites
        • 1. Setting up Hardhat
        • 2. Writing contracts
        • 3. Testing in mocked mode
        • 4. Deploying the contract
        • 5. Interacting with the contract
  • Tutorials
    • See all tutorials
  • Smart contract
    • Key features
    • Configuration
    • FhEVM contracts
    • Supported types
    • Operations on encrypted types
    • Access Control List
      • ACL examples
    • Encrypted Inputs
    • Decryption
      • Decryption
      • Decryption in depth
      • Re-encryption
    • If sentences
    • Branching in FHE
    • AsEbool, asEuintXX, asEaddress and asEbytesXX operations
    • Generate random numbers
    • Error handling
    • Gas estimation
    • Debug decrypt
    • Using Foundry
  • Frontend
    • Setup
    • Build a web application
    • Using React.js
    • Using Next.js
    • Using Vue.js
    • Using Node or Typescript
    • Using the CLI
    • Common webpack errors
  • Explanations
    • Architectural overview
    • FHE on blockchain
    • fhEVM components
    • Encryption, decryption, re-encryption, and computation
  • References
    • Table of all addresses
    • Smart contracts - fhEVM API
    • Frontend - fhevmjs lib
    • Repositories
  • Developer
    • Contributing
    • Development roadmap
    • Release note
    • Feature request
    • Bug report
    • Status
Powered by GitBook

Libraries

  • TFHE-rs
  • Concrete
  • Concrete ML
  • fhEVM

Developers

  • Blog
  • Documentation
  • Github
  • FHE resources

Company

  • About
  • Introduction to FHE
  • Media
  • Careers
On this page
  • Prerequisites
  • Understanding the example contract
  • Step 1. Importing required libraries and contracts.
  • Step 2. Contract construction
  • Going further

Was this helpful?

Export as PDF
  1. Getting Started
  2. Quick Start
  3. Hardhat

2. Writing contracts

Previous1. Setting up HardhatNext3. Testing in mocked mode

Last updated 3 months ago

Was this helpful?

This document explains how to write confidential smart contract using fhEVM in Hardhat projects.

Prerequisites

Before proceeding, ensure you have:

  • A working Hardhat environment set up (see ).

  • Basic knowledge of Solidity.

  • An understanding of ERC20 tokens.

Understanding the example contract

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.

Step 1. Importing required libraries and contracts.

pragma solidity ^0.8.24;

import "fhevm/lib/TFHE.sol";
import "fhevm/config/ZamaFHEVMConfig.sol";
import "fhevm-contracts/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol";
  • 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.

Step 2. Contract construction

contract MyConfidentialERC20 is SepoliaZamaFHEVMConfig, ConfidentialERC20Mintable {
  constructor(string memory name_, string memory symbol_) ConfidentialERC20Mintable(name_, symbol_, msg.sender) {}
}
  • This contract inherits SepoliaZamaFHEVMConfig and ConfidentialERC20Mintable.

  • The constructor initializes the ERC20 token with a name and symbol, setting the deployer as the initial owner.

Going further

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.

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


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 .

Smart Contract
the fhEVM-contracts documentation
previous section