Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This tutorial covers the essentials steps to quickly write and deploy confidential ERC20 smart contract using the Zama Plug in.
Remix is a powerful in-browser IDE for Ethereum smart contract development. It offers a fast, intuitive way to write and deploy confidential ERC20 contracts using Zama’s fhEVM plugin—no local setup required.
In this tutorial, you will learn to:
Set up Remix for fhEVM development.
Connect your wallet (e.g., MetaMask) to Remix.
Deploy a ConfidentialERC20 contract.
Interact with your deployed contract directly in the Remix interface.
By the end, you’ll have a working confidential ERC20 token on Sepolia network and know how to perform encrypted transactions.
After deploying your first fhEVM contract using Remix, this guide shows you how to interact with it directly in Remix using the Zama Plugin.
Before interacting with your deployed contract, ensure the following:
Deployment completed: You have successfully deployed the MyConfidentialERC20
contract (see Step 3).
MetaMask wallet: Your MetaMask wallet is connected to the Sepolia testnet(see Step 2). You might want to prepare an additional wallet as the receiver to mock the transfer function.
Zama Plugin in Remix: The Zama Plugin is installed and accessible in Remix (see Step 1).
To perform transactions directly in Remix, your contract needs to be connected to the Zama Plugin:
Open Deploy & run transaction from the side bar
In "Deployed Contract", copy the address of the MYCONFIDENTIALERC20
contract that you just deployed.
Open the Zama Plugin from the side menu.
Paste the contract address into the "At address" field under the Deploy section.
Click At address.
If the address was entered correctly, the MyConfidentialERC20.sol
contract will be displayed in the "Deployed Contract" inside the Zama Plugin.
Click to expand the contract, you'll see the interface to interact with all the functions of your contract. ConfidentialERC20Mintable
supports all standard ERC-20 functions, but adapted for encrypted values, including:
transfer
: Securely transfers encrypted tokens.
approve
: Approves encrypted amounts for spending.
transferFrom
: Transfers tokens on behalf of another address.
balanceOf
: Returns the encrypted balance of an account.
totalSupply
: Returns the total token supply.
From here, you can mint confidential ERC20 token to your account:
Copy your wallet address from MetaMask.
Inside Zama Plugin, click to expand the mint function of your contract.
Enter your wallet address and the amount of tokens to mint (e.g., 1000
).
Click Submit
.
Confirm the transaction in MetaMask.
Once sccussful, you should see the message in the terminal.
After a successful mint transaction, click the totalSupply to reflect the minted tokens (e.g., 1000
).
To verify your account balance:
Click to expand the balanceOf function.
Enter your wallet address.
Click Submit
to verify your account balance.
Your balance is stored as encrypted data using FHE. No one else can view if except you.
To view the balance in plaintext:
Click the re-encrypt option
Confirm the transaction in Metamask
You can see that the ciphertext is decrypted and your balance is the amount that you just minted.
To transfer confidential ERC20 tokens to another account:
Copy the address of the receiver's wallet.
Click transfer to expand the function, set the following parameters:
To: Enter the wallet address of reveiver.
encryptedAmount: Specify the amount that you want to transfer (e.g.1000
). Choose euint64
.
inputProof: Check the input box.
Click Submit to proceed.
Confirm the transaction in MetaMask.
If successful, you should see the message in the terminal.
After making a transfer, you can verify your updated account balance:
Use the balanceOf function again to check the updated balance of your original account (see the Step 5: Check your balance.)
Perform re-encryption to confirm the changes, you should see the remaining token in your account.(e.g., 900
tokens remaining).
Always re-encrypt to validate ciphertext transformations and confirm operations.
🎉 Congratulations on completing this tutorial! You’ve taken the first step in building confidential smart contracts using fhEVM. It's time now to take the next step and build your own confidential dApps!
To continue your journey and deepen your knowledge, explore the resources below.
Read the Whitepaper: Understand the core technology behind fhEVM, including its cryptographic foundations and use cases.
See more demos and tutorials: Expand your skills with hands-on demos and tutorials crafted to guide you through various real-world scenarios.
Try out AI coding assistant: If you have a chatGPT plus account, try out our custom ChatGPT model tailored for Solidity and fhEVM developers.
Use out-of-box templates and frameworks designed for developers to build confidential dapps easily.
Smart contract development
Hardhat Template: A developer-friendly starting point for building and testing smart contracts on fhEVM.
fhEVM Contracts Library: Access standardized contracts for encrypted operations.
Frontend development
React.js Template: Quickly develop FHE-compatible dApps using a clean React.js setup.
Next.js Template: Build scalable, server-rendered dApps with FHE integration.
Vue.js Template: Develop responsive and modular dApps with FHE support in Vue.js.
Join the community to shape the future of blockchain together with us.
Discord: Join the community to get the latest update, have live discussion with fellow developers and Zama team.
Community Forum: Get support on all technical questions related to fhEVM
Zama Bounty Program: Participate to tackle challenges and earn rewards in cash.
In this guide, you'll learn how to connect your wallet and the Zama Plugin in Remix IDE to interact with fhEVM smart contracts.
Before starting, ensure you have the following:
MetaMask or another Ethereum-compatible wallet installed.
Zama Plugin installed in Remix IDE ()
Note thate when using Remix to connect a wallet, issues may arise if multiple wallet extensions are installed (e.g., MetaMask, Phantom). This is a known issue of Remix that can affect wallet connection functionality. If you encounter errors, consider keeping only MetaMask as the active wallet extension, removing other wallet extensions, and refreshing Remix cookies and try to reconnect.
If you're using Metamask, the Sepolia testnet should be pre-configured. Follow the steps to set it up:
Open MetaMask.
Click the network dropdown at the top left corner, and select Sepolia Test Network.
Ensure you have Sepolia ETH available. If you don’t have enough ETH, use a Sepolia faucet to request free SepoliaETH for testing:
If Sepolia isn’t visible:
Go to Settings > Advanced.
Toggle Show test networks to ON.
If Sepolia isn’t pre-configured in your wallet, add it manually:
Open your wallet’s network settings.
Click Add Network or Add Network Manually.
Enter the following details:
Network Name: Sepolia
RPC URL: (provided by your node provider, e.g., Alchemy or Infura)
Chain ID: 11155111
Currency Symbol: SepoliaETH
Block Explorer URL: https://sepolia.etherscan.io
Zama Plugin provides the Zama Coprocessor - Sepolia configuration that ensures Remix and the wallet are properly set up to interact with fhEVM smart contracts.
To complete the configuration:
Open the Zama Plugin in Remix from the side pannel.
Click Connect your wallet.
Confirm the connection in MetaMask.
In the Zama Plugin, select Zama Coprocessor - Sepolia.
Click Use this configuration to finalize the setup.
Once successful, you should see the green text in the terminal indicating that the configuration is ready.
Follow the steps to connect your wallet to Remix:
Open Remix and navigate to Deploy & run transactions.
Under Environment, select Injected Provider - MetaMask.
MetaMask will prompt a connection request. Click Connect to proceed.
Choose your wallet address in Account.
Now that your wallet is connected and your SepoliaETH balance is ready, you can proceed to deploy the ConfidentialERC20Mintable
contract!
This guide helps you set up the Zama Plugin in the official Remix IDE, enabling seamless development and management of smart contracts using the fhEVM.
Before starting, make sure you have the following:
A web browser (such as Chrome, Firefox).
Basic familiarity with Ethereum smart contracts.
A crypto wallet (we recommend using MetaMask for this tutorial).
Zama Plugin allows you to interact with confidential contracts directly within Remix. To set it up:
Open the Remix IDE by navigating to .
In the left sidebar, click on the Plugin Manager.
In the Plugin Manager, select Connect to a Local Plugin.
Use the following configurations:
Plugin Name (required) : Enter Zama
.
URL(required): Enter https://remix.zama.ai/
.
Type of connection(required): Select Iframe
Location in remix (required):Select Side Panel
Click OK
.
Now that you've configured the plugin, you are able to deploy and interact with fhEVM encrypted contracts directly directly via Remix interface. Next, let's dive into the contract deployment.
In this tutorial, you'll learn how to deploy a confidential token contract using Zama's fhEVM. We'll create MyConfidentialERC20.sol
to demonstrate the essential features.
Ensure the following before deploying the smart contract:
The Zama Plugin installed is installed in the Remix IDE(see ).
Your wallet is connected to the Sepolia testnet(see ).
First, let's create a file for our confidential ERC20 contract:
Open the File explorer from the side menu.
Navigate to the contracts folder.
Click the Create new file icon.
Name the file MyConfidentialERC20.sol
and press Enter.
The foundational structure includes importing Zama's libraries and connecting to Sepolia's fhEVM configuration.
Copy the following code in the MyConfidentialERC20.sol
that you just created:
It should appear as follows:
Remix automatically saves any changes as you type. Upon saving, it imports the following libraries:
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.
Next, we'll enhance our contract by importing the fhevm-contracts
library.
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
The fhevm-contracts
library includes the ConfidentialERC20Mintable
contract, which is an extention of ConfidentialERC20
with minting capabilities, providing:
Private token transfers and encrypted balances
Minting functionality for authorized addresses
Full ERC20 compatibility
It inherits all base ConfidentialERC20
features while adding secure token creation and distribution capabilities.
To use ConfidentialERC20Mintable
contract, simply update your MyConfidentialERC20.sol
with the following code:
It should appear as follows:
Now the contract is ready, the next step is to compile it:
Select MyConfidentialERC20.sol
.
Go to Solidity compiler in Remix.
Click Compile.
If successful, you will see a green checkmark on the Solidity Compiler, indicating "Compilation successful"
Now the contract is ready to be deployed:
Make sure that the envrionment is set up properly
Envrionment: Injected Provider - Metamask
Account: Your wallet address
Expand the Deploy section.
Fill the constructor parameters:
Name: Your token’s name (e.g., "My Private Token").
Symbol: Token symbol (e.g., "MPT").
Click Transact and confirm the transaction in MetaMask.
Once successfully deployed, your contract will appear under Deployed Contracts. You can also view your contract on Etherscan by clicking the contract address.
By following these steps, you’ve successfully created and deployed an confidential ERC-20 token using Zama's fhEVM!🎉 Let's see how the transaction works in the next chapter.
This tutorial guides you to start quickly with Zama’s Fully Homomorphic Encryption (FHE) technology for building confidential smart contracts.
In about 20 minutes, you will:
Build your first confidential ERC20 contract that leverages FHE.
Deploy the contract on the Sepolia Network.
Mint tokens and perform transactions in FHE.
Build a frontend application for your contract.
A basic understanding of Solidity library and Ethereum.
A certain amount of Sepolia ETH available.
If you don’t have enough ETH, use a Sepolia faucet to request free SepoliaETH for testing such as or .
The contract that you will build with this tutorial is called ConfidentialERC20Mintable
— a privacy-preserving ERC20 implementation that leverages FHE to keep balances and transactions confidential. To understand this contract, let’s first introduce the foundational concepts.
RC20
ERC20 is a widely used token standard on Ethereum that defines a set of rules for creating and managing fungible tokens. These tokens are efficient but lack privacy — balances and transactions are visible to anyone on the blockchain.
Confidential ERC20
Zama’s ConfidentialERC20
introduces privacy to ERC20 tokens by storing balances and transactions in an encrypted format using FHE.
The ConfidentialERC20
contract still supports standard ERC20 functions such as transfer
, approve
, transferFrom
, balanceOf
, and totalSupply
but ensures these operations are processed securely with encrypted data.
Confidential ERC-20 Mintable
The contract that we will build in this tutorial is ConfidentialERC20Mintable
. It's built on top of ConfidentialERC20
by adding secure minting capabilities. This allows authorized accounts to create new tokens, while maintaining the privacy guarantees of encrypted balances and transactions.
The ConfidentialERC20Mintable
contract ensures:
Enhanced privacy: Balances are stored as encrypted values (euint64
), preventing public inspection of account balances.
Secure transactions: Token transfers are processed securely, maintaining confidentiality of amounts.
Owner visibility: Only account owners can decrypt and view their balances.
Choose your path and get started:
See more details in .
To explore the implementation details of ConfidentialERC20, check out the .
– Rapid in‐browser setup, great for learning and fast prototyping.
– Full-fledged development environment, suitable for production.
This tutorial covers the essential steps to quickly write and deploy a confidential ERC20 smart contract using the fhEVM Hardhat template.
Hardhat is a flexible, extensible development environment for Ethereum, providing a robust toolkit for compiling, testing, and deploying smart contracts. With Zama’s fhEVM integration, you can develop confidential ERC20 contracts locally and then seamlessly deploy them to a real fhEVM node.
In this tutorial, you will learn to:
Set up a Hardhat project with the fhEVM Hardhat Template.
Write confidential contracts utilizing encrypted data types.
Test your contracts in mocked mode (for rapid feedback and coverage).
Deploy your confidential ERC20 contract to the Sepolia test network.
Interact with your deployed contract, including performing encrypted transfers.
By following these steps, you’ll get familiar with the complete development workflow using Hardhat, and be able to build, test and deploy confidential ERC20 smart contracts on Sepolia testnet.
This guide will walk you through installing all necessary dependencies from scratch, preparing you for developing and deploying fhEVM smart contracts using Hardhat.
To use Hardhat to build and deploy confidential smart contract, you need to have the following:
Node.js (v20 or later)
A package manager: npm
, yarn
, or pnpm
Git for version control
Foundry for using the command cast
If you already have these installed, skip ahead to 1. Setting Up Hardhat.
To run the installation commands, open a terminal:
Use your system's built-in terminal (e.g., Terminal on macOS, Command Prompt or PowerShell on Windows, or a Linux shell).
Alternatively, use the integrated terminal in a IDE such as Visual Studio Code (VS Code).
VS code provide the official Hardhat extension for an enhanced development experience with Hardhat.
Instead of installing Node.js directly, we recommend using Node Version Manager (nvm
), which allows you to manage multiple versions of Node.js:
Install Node.js using nvm. This installs the latest version of Node.js:
Install pnpm (optional but recommended for better speed and efficiency). After installing Node.js, you automatically have npm, so run:
Alternatively, you can continue using npm
or yarn
if you prefer.
Git is required for managing source code, cloning repositories, and handling version control. Install Git based on your operating system:
Linux: Use your distribution's package manager (e.g., sudo apt-get install git
on Ubuntu/Debian).
Windows: Download Git for Windows.
macOS: Install via Homebrew with brew install git
or download Git.
We will need the command cast
in our tutorial. This command is available with installing Foundry.
Install Foundry using the official installer:
Reload your terminal configuration:
Run the Foundry installer:
This will install all Foundry components, including cast
, forge
, anvil
, and chisel
.
To verify the installation, run:
You now have all the necessary dependencies installed. Continue to 1. Setting Up Hardhat to begin creating and deploying your FHE smart contracts!
This guide walks you through deploying your Confidential ERC20 smart contract on the Sepolia test network.
Before proceeding, ensure you have:
A configured Hardhat project using the fhEVM Hardhat Template (see previous sections).
A crypto wallet installed (e.g., Metamask).
Some Sepolia ETH available for testing. If you don’t have enough ETH, use a Sepolia faucet to request free SepoliaETH for testing:
Generate a mnemonic seed for accounts using cast
:
(cast
is a Foundry function. If you don't have Foundry installed, run curl -L https://foundry.paradigm.xyz | bash
first):
Obtain a Sepolia RPC URL:
Sign up for a node provider such as Alchemy - https://www.alchemy.com/
or Infura - https://infura.io/
. Copy your Sepolia RPC URL.
Open the .env
file:
Past your mnemonic in the code:
MNEMONIC=<Your mnemonic generated>
Paste a Sepolia RPC URL:
SEPOLIA_RPC_URL=<Your node provider URL>
Verify generated accounts:
Open your wallet (e.g, MetaMask)
Import the first 2 accounts (e.g., Alice and Bob) into your wallet with their private keys.
Fund these 2 accounts with some Sepolia ETH.
In the deploy/
directory, there is a preconfigured deploy.ts
file that handles the deployment process. You can customize it or add your own scripts.
To deploy the contracts to Sepolia, run:
Once deployment is successful, you should see a console output that includes the contract address such as:
You can verify this contract on Sepolia Etherscan by searching for the deployed address.
Congratulations! 🎉 You have deployed your first confidential ERC20 smart contract. Let's mint a few tokens and perform some encrypted transactions!
This tutorial walks you through performing tests in the mocked mode provided by the fhEVM Hardhat template.
Before proceeding, ensure you have:
A configured Hardhat project using the fhEVM Hardhat template. (See the previous section)
Basic knowledge of Solidity and Hardhat testing. (See the Hardhat testing documentation)
fhEVM provides a mocked mode in Hardhat that allows for:
Faster testing on a local Hardhat network.
The ability to analyze code coverage.
A simulated version of encrypted types (they are not truly encrypted).
Access to Hardhat features such as snapshots (evm_snapshot
), time manipulation (evm_increaseTime
), and debugging (console.log
).
To learn more about the fhEVM mocked mode, refer to the README in the fhEVM Hardhat template repository.
To run tests in mocked mode, open a terminal in your project's root directory and execute:
This command runs all tests locally in mocked mode. You should see the test results in your console.
For most development and demonstration scenarios, mocked mode is sufficient. However, for production-ready development and a real testing environment, you need to run your tests on a real network where the coprocessor is deployed for example Sepolia. Refer to the next section on how to deploy your contract on Sepolia test network.
After deploying your first fhEVM contract using Hardhat, this guide shows you how to interact with it using Hardhat tasks.
Before interacting with your deployed contract, ensure the following:
Deployment completed: You have successfully deployed the MyConfidentialERC20
contract (see previous section)
Contract address: You have saved the deployed contract address
Sepolia ETH: You have some Sepolia ETH in your wallet for transaction fees
Environment setup: Your .env
file is properly configured with your private key
First, let's mint some confidential tokens to your account:
Once successful, you'll see a transaction confirmation in the terminal that looks like this:
You can check the total supply of tokens to confirm your mint was successful:
Once successful, you'll see a transaction confirmation in the terminal:
To verify your account balance:
Note to remind yourself what was are the private keys of the accounts of the MNEMONIC SEED you can always check it by running:
Once successful, you'll see a transaction confirmation in the terminal.
To transfer confidential tokens to another account:
Once successful, you'll see a transaction confirmation in the terminal.
After the transfer, you can check both accounts balances:
If both balances have changed accordingly the transaction was successful.
Here's a complete list of available Hardhat tasks for interacting with your contract:
mint
: Mint new encrypted tokens
transfer
: Transfer encrypted tokens to another address
balance
: Check encrypted balance of an account
totalSupply
: Get the total token supply
For detailed help on any task, run:
🎉 Congratulations on completing this tutorial! You’ve taken the first step in building confidential smart contracts using fhEVM. It's time now to take the next step and build your own confidential dApps!
To continue your journey and deepen your knowledge, explore the resources below.
Use out-of-box templates and frameworks designed for developers to build confidential dApps easily.
Smart contract development
Frontend development
Join the community to shape the future of blockchain together with us.
This guide walks you through setting up your Hardhat environment using Zama's fhEVM Hardhat template.
Open the repository: Zama fhEVM Hardhat Template
Click "Use this template" to create a new repository under your GitHub account.
Clone the repository you have created to your local environment
Copy the repository URL of your newly created repository.
Open a terminal and run:
Copy the environment configuration template:
Install project dependencies: Depending on your package manager, run one of the following:
contracts/
: Write your Solidity smart contracts here.
test/
: Place your test scripts for smart contract testing.
deploy/
: Deployment scripts for deploying your contracts.
hardhat.config.js
: The pre-configured Hardhat setup file for deploying on Sepolia.
.env
: The environment file that stores sensitive or environment-specific variables such as private keys and API keys.
To learn more about Hardhat, refer to the official Hardhat documentation.
You are now ready to start building your confidential smart contracts with fhEVM!
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.
: Understand the core technology behind fhEVM, including its cryptographic foundations and use cases.
: Expand your skills with hands-on demos and tutorials crafted to guide you through various real-world scenarios.
: If you have a ChatGPT plus account, try out our custom ChatGPT model tailored for Solidity and fhEVM developers.
: A developer-friendly starting point for building and testing smart contracts on fhEVM.
: Access standardized contracts for encrypted operations.
: Quickly develop FHE-compatible dApps using a clean React.js setup.
: Build scalable, server-rendered dApps with FHE integration.
: Develop responsive and modular dApps with FHE support in Vue.js.
: Join the community to get the latest update, have live discussion with fellow developers and Zama team.
: Get support on all technical questions related to fhEVM
: Participate to tackle challenges and earn rewards in cash.