5. Interacting with the contract

After deploying your first fhEVM contract using Hardhat, this guide shows you how to interact with it using Hardhat tasks.

Prerequisites

Before interacting with your deployed contract, ensure the following:

  • Deployment completed: You have successfully deployed the MyConfidentialERC20 contract (see previous section)

  • Contract address: You have saved the deployed contract address

  • Sepolia ETH: You have some Sepolia ETH in your wallet for transaction fees

  • Environment setup: Your .env file is properly configured with your private key

Step 1: Mint tokens to your account

First, let's mint some confidential tokens to your account:

# Mint 1000 tokens to your account by replacing recipient-address with your address
npx hardhat mint --to <recipient-address> --amount 1000 --network sepolia

Once successful, you'll see a transaction confirmation in the terminal that looks like this:

Starting mint process...
Contract address: 0x1...26
Minting 1000 tokens to address: 0x1...26
Transaction submitted, waiting for confirmation...
✅ Mint transaction successful!
Transaction hash: 0x1...26
1000 tokens were minted to 0x1....26

Step 2: Verify total supply

You can check the total supply of tokens to confirm your mint was successful:

# Check the total supply
npx hardhat totalSupply --network sepolia

Once successful, you'll see a transaction confirmation in the terminal:

✅ Retrieved total supply successfully
----------------------------------------
Total Supply: 1000 tokens
----------------------------------------

Step 3: Check your balance

To verify your account balance:

# Check your encrypted balance by replacing <private-key> with the private key of the account you want to check
# You can get the private key by running 'npx hardhat get-accounts --num-accounts 5'
npx hardhat balance --privatekey <private-key> --network sepolia

Note to remind yourself what was are the private keys of the accounts of the MNEMONIC SEED you can always check it by running:

npx hardhat get-accounts --num-accounts 5

Once successful, you'll see a transaction confirmation in the terminal.

✅ Retrieved balance handle successfully
----------------------------------------
Address: 0x1..59
Balance: 1000 tokens
----------------------------------------

Step 4: Transfer tokens

To transfer confidential tokens to another account:

# Transfer tokens from your account to another address
# Replace <private-key> with the private key of the sending account
# Replace <recipient-address> with the destination wallet address
# Adjust the amount (100) as needed
npx hardhat transfer --privatekey <private-key> --to <recipient-address> --amount 100 --network sepolia

Once successful, you'll see a transaction confirmation in the terminal.

Starting transfer process...
Contract address: 0x1...26
From: 0x1...59
To: 0xA...4D
Amount: 100 tokens
Encrypting and proving in 9.4s
Verifying in 8.7s
Submitting transfer transaction...
Waiting for confirmation...
----------------------------------------
✅ Transfer successful!
Transaction hash: 0xc..13
Transferred 100 tokens to 0xA..4D

Step 5: Verify updated balances

After the transfer, you can check both accounts balances:

# Check sender's updated balance after transfer
# Replace <private-key> with the private key of the senders account
npx hardhat balance --privatekey <private-key> --network sepolia

# Check recipient's updated balance after receiving transfer
# Replace <private-key> with the private key of the recipient account
npx hardhat balance --privatekey <private-key> --network sepolia

If both balances have changed accordingly the transaction was successful.

Available Tasks

Here's a complete list of available Hardhat tasks for interacting with your contract:

  • mint: Mint new encrypted tokens

  • transfer: Transfer encrypted tokens to another address

  • balance: Check encrypted balance of an account

  • totalSupply: Get the total token supply

For detailed help on any task, run:

npx hardhat help <task-name>

Next steps

🎉 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!

1. Resources

To continue your journey and deepen your knowledge, explore the resources below.

  • Read the white paper: 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.

2. Tools

Use out-of-box templates and frameworks designed for developers to build confidential dApps easily.

Smart contract development

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.

3. Community

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.

Last updated

Was this helpful?