fhEVM
WebsiteLibrariesProduct & ServicesDevelopersSupport
0.6
0.6
  • Welcome to fhEVM
  • White paper
  • Getting Started
    • Overview
    • Quick Start
      • Remix
        • 1. Setting up Remix
        • 2. Connect your wallet to Remix
        • 3. Deploying ConfidentialERC20
        • 4. Interacting with the contract
      • Hardhat
        • Prerequisites
        • 1. Setting up Hardhat
        • 2. Writing contracts
        • 3. Testing in mocked mode
        • 4. Deploying the contract
        • 5. Interacting with the contract
  • Tutorials
    • See all tutorials
  • Smart contract
    • Key features
    • Configuration
    • FhEVM contracts
    • Supported types
    • Operations on encrypted types
    • Access Control List
      • ACL examples
    • Encrypted Inputs
    • Decryption
      • Decryption
      • Decryption in depth
      • Re-encryption
    • If sentences
    • Branching in FHE
    • AsEbool, asEuintXX, asEaddress and asEbytesXX operations
    • Generate random numbers
    • Error handling
    • Gas estimation
    • Debug decrypt
    • Using Foundry
  • Frontend
    • Setup
    • Build a web application
    • Using React.js
    • Using Next.js
    • Using Vue.js
    • Using Node or Typescript
    • Using the CLI
    • Common webpack errors
  • Explanations
    • Architectural overview
    • FHE on blockchain
    • fhEVM components
    • Encryption, decryption, re-encryption, and computation
  • References
    • Table of all addresses
    • Smart contracts - fhEVM API
    • Frontend - fhevmjs lib
    • Repositories
  • Developer
    • Contributing
    • Development roadmap
    • Release note
    • Feature request
    • Bug report
    • Status
Powered by GitBook

Libraries

  • TFHE-rs
  • Concrete
  • Concrete ML
  • fhEVM

Developers

  • Blog
  • Documentation
  • Github
  • FHE resources

Company

  • About
  • Introduction to FHE
  • Media
  • Careers
On this page
  • Prerequisites
  • Step 1: Mint tokens to your account
  • Step 2: Verify total supply
  • Step 3: Check your balance
  • Step 4: Transfer tokens
  • Step 5: Verify updated balances
  • Available Tasks
  • Next steps
  • 1. Resources
  • 2. Tools
  • 3. Community

Was this helpful?

Export as PDF
  1. Getting Started
  2. Quick Start
  3. Hardhat

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.

2. Tools

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

Smart contract development

Frontend development

3. Community

Join the community to shape the future of blockchain together with us.

Previous4. Deploying the contractNextSee all tutorials

Last updated 13 days ago

Was this helpful?

: Understand the core technology behind fhEVM, including its cryptographic foundations and use cases.

: Expand your skills with hands-on demos and tutorials crafted to guide you through various real-world scenarios.

: If you have a ChatGPT plus account, try out our custom ChatGPT model tailored for Solidity and fhEVM developers.

: A developer-friendly starting point for building and testing smart contracts on fhEVM.

: Access standardized contracts for encrypted operations.

: Quickly develop FHE-compatible dApps using a clean React.js setup.

: Build scalable, server-rendered dApps with FHE integration.

: Develop responsive and modular dApps with FHE support in Vue.js.

: Join the community to get the latest update, have live discussion with fellow developers and Zama team.

: Get support on all technical questions related to fhEVM

: Participate to tackle challenges and earn rewards in cash.

Read the white paper
See more demos and tutorials
Try out AI coding assistant
Hardhat Template
fhEVM Contracts Library
React.js Template
Next.js Template
Vue.js Template
Discord
Community Forum
Zama Bounty Program