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.