Define the mint function to mint tokens by encrypting the amount and sending it to the contract. This process uses the FHEVM instance to create a encrypted input for the minting transaction.
Explanation: This function encrypts the mint amount and then calls the _mint function in the contract, passing the encrypted data. This way, the actual minting amount remains hidden, ensuring confidentiality in token minting.
Step 7: Reading Encrypted Balance
Use the reencrypt function to securely retrieve and decrypt the user's balance. This function uses a public-private key pair along with an EIP-712 signature to ensure secure decryption.
Behind the scenes, the instance calls the gateway API to request encryption of the balance. The gateway then checks access permissions through ACL to verify whether the user is authorized to access the ciphertext. If authorized, the gateway makes a secure call to the Key Management Service (KMS) for re-encryption. The KMS re-encrypts the balance and returns it to the client DApp, which then decrypts the balance locally using the user’s private key.
Step 8: Finally, run the following:
npm install
npm run dev
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.