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.
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 https://remix.ethereum.org.
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.
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 ).
MetaMask wallet: Your MetaMask wallet is connected to the Sepolia testnet(see ). 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 ).
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:
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.
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.
See more details in .
Use the balanceOf function again to check the updated balance of your original account (see the .)
: 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.
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 (See Setting up Remix)
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!