3. Deploying ConfidentialERC20
Last updated
Was this helpful?
Last updated
Was this helpful?
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 Step 1).
Your wallet is connected to the Sepolia testnet(see Step 2).
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
See more details in the fhEVM-contracts documentation.
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.