Deploy using our tutorial
Step 1: Clone our tutorial for encrypted-erc20-dapp github repo.
Step 2: Replace the contract ABI from "erc20ABI.json" in the src file with your deployed ABI file.
Step 3: Assuming you have replaced your ABI in the project src directory, replace the smart contract address in the ConfidentialERC20.jsx file.
Step 4: We need to create an fhevm instance on the client. It expects us to provide a network public key in order to encrypt data locally. Add this in src/utils/fhevm.jsx file:
Step 5: We can use our instance to encrypt data using the network's public key. Go to ConfidentialERC20.jsx and add this to handleAmountMintChange function:
Step 6: Inside mint()
function we can make a transaction to mint a hidden amount. Add this to mint function in the same ConfidentialERC20.jsx file:
Now if we press the "mint" button it should mint tokens. In order to check that this worked, we will read our own balance, and to do that using reencrypt.
Step 7: To make "decrypt own balance" button to work, we provide the users's publicKey as well as the EIP-712 signature, then decrypt the return value using our fhevm instance to read our balance. Add this snippet in the reencrypt function in ConfidentialERC20.jsx:
TFHE.reencrypt
enables confidential value decryption, granting access exclusively to the user. This method involves transforming the ciphertext encrypted under the global FHE key into another encrypted ciphertext. This transformation utilizes a temporary public key provided by the user. Subsequently, the user can decrypt the new ciphertext using the corresponding temporary private key, all of which occurs on the client side.
Step 8: Finally, run the following:
You should see a screen like this popping up at the local host:
Congrats! We have successfully deployed a confidential ERC-20 contract. Now you can press decrypt your balance and it would return the mint amount. Please reach out to us if you have any further questions.
Last updated