ERC7984Example

Category: Identity | Difficulty: Beginner | Chapters: Erc7984 | Concept: Minimal ERC7984 token with confidential mint + transfer

Minimal ERC7984 confidential token example.

Why this example

This example focuses on Minimal ERC7984 token with confidential mint + transfer. It is designed to be self-contained and easy to run locally.

Quick start

npm install
npm run test:mocked -- test/identity/ERC7984Example.test.ts

Dependencies

None

Deployment plan

Step
Contract
Args
Saves As

1

ERC7984Example

$deployer

token

Contract and test

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import {FHE, externalEuint64} from "@fhevm/solidity/lib/FHE.sol";
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC7984} from "@openzeppelin/confidential-contracts/token/ERC7984/ERC7984.sol";

/**
 * @title ERC7984Example
 * @author Gustavo Valverde
 * @notice Minimal ERC7984 confidential token example.
 * @dev Example for fhEVM Examples - OpenZeppelin Confidential Contracts
 *
 * @custom:category identity
 * @custom:chapter erc7984
 * @custom:concept Minimal ERC7984 token with confidential mint + transfer
 * @custom:difficulty beginner
 * @custom:deploy-plan [{"contract":"ERC7984Example","saveAs":"token","args":["$deployer"]}]
 */
contract ERC7984Example is ERC7984, Ownable, ZamaEthereumConfig {
    /**
     * @notice Initialize the minimal ERC7984 token
     * @param initialOwner The address that will own the contract
     */
    constructor(address initialOwner)
        ERC7984("Confidential Token", "CTK", "ipfs://erc7984-example")
        Ownable(initialOwner)
    {}

    /**
     * @notice Mint confidential tokens (owner-only)
     * @param to Recipient
     * @param amount Encrypted amount
     * @param inputProof Proof for the encrypted input
     */
    function mint(address to, externalEuint64 amount, bytes calldata inputProof) external onlyOwner {
        _mint(to, FHE.fromExternal(amount, inputProof));
    }
}

Pitfalls to avoid

No pitfalls are highlighted in the tests for this example.

API Reference

Overview

Minimal ERC7984 confidential token example.

Developer Notes

Example for fhEVM Examples - OpenZeppelin Confidential Contracts

constructor

Initialize the minimal ERC7984 token

Parameters

Name
Type
Description

initialOwner

address

The address that will own the contract

mint

Mint confidential tokens (owner-only)

Parameters

Name
Type
Description

to

address

Recipient

amount

externalEuint64

Encrypted amount

inputProof

bytes

Proof for the encrypted input

Last updated