4. Deploying the contract

This guide walks you through deploying your Confidential ERC20 smart contract on the Sepolia test network.

Prerequisites

Before proceeding, ensure you have:

  • A configured Hardhat project using the fhEVM Hardhat Template (see previous sections).

  • A crypto wallet installed (e.g., Metamask).

  • Some Sepolia ETH available for testing. If you don’t have enough ETH, use a Sepolia faucet to request free SepoliaETH for testing:

Step 1. Preparing for deployment

  1. Generate a mnemonic seed for accounts using cast:

    • (cast is a Foundry function. If you don't have Foundry installed, run curl -L https://foundry.paradigm.xyz | bash first):

cast wallet new-mnemonic
  1. Obtain a Sepolia RPC URL:

    • Sign up for a node provider such as Alchemy - https://www.alchemy.com/ or Infura - https://infura.io/. Copy your Sepolia RPC URL.

  2. Open the .env file:

    • Past your mnemonic in the code:

      • MNEMONIC=<Your mnemonic generated>

    • Paste a Sepolia RPC URL:

      • SEPOLIA_RPC_URL=<Your node provider URL>

  3. Verify generated accounts:

npx hardhat get-accounts --num-accounts 5

Step 2. Funding your wallet

  1. Open your wallet (e.g, MetaMask)

  2. Import the first 2 accounts (e.g., Alice and Bob) into your wallet with their private keys.

  3. Fund these 2 accounts with some Sepolia ETH.

Step 3. Deploying the contract

In the deploy/ directory, there is a preconfigured deploy.ts file that handles the deployment process. You can customize it or add your own scripts.

To deploy the contracts to Sepolia, run:

# Using npm
npm run deploy-sepolia

# Using yarn
yarn deploy-sepolia

# Using pnpm
pnpm deploy-sepolia

Step 4. Verify the deployment

Once deployment is successful, you should see a console output that includes the contract address such as:

MyConfidentialERC20: 0x1234........ABCD

You can verify this contract on Sepolia Etherscan by searching for the deployed address.


Congratulations! 🎉 You have deployed your first confidential ERC20 smart contract. Let's mint a few tokens and perform some encrypted transactions!

Last updated

Was this helpful?