ERC7984ERC20WrapperExample

Category: Identity | Difficulty: Advanced | Chapters: Erc7984 | Concept: ERC7984ERC20Wrapper (ERC20 ↔ ERC7984) + KYC-gated wrap/unwrap

Wrap a public ERC20 into a confidential ERC7984 token, and unwrap back via public decryption

Why this example

This example focuses on ERC7984ERC20Wrapper (ERC20 ↔ ERC7984) + KYC-gated wrap/unwrap. It is designed to be self-contained and easy to run locally.

Quick start

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

Dependencies

  • SimpleKycRegistry

  • MockUSDC

Deployment plan

Step
Contract
Args
Saves As

1

SimpleKycRegistry

$deployer

kyc

2

MockUSDC

$deployer, 0

usdc

3

ERC7984ERC20WrapperExample

$deployer, @usdc, @kyc

wrapper

Contract and test

Pitfalls to avoid

  • should reject wrapping for non-KYC users

  • should not allow public decrypt of confidential balances

API Reference

Overview

Wrap a public ERC20 into a confidential ERC7984 token, and unwrap back via public decryption

Developer Notes

Example for fhEVM Examples - OpenZeppelin Confidential Contracts

kyc

The KYC registry for compliance checks

NotKycApproved

Error thrown when a non-KYC-approved address attempts an operation

Parameters

Name
Type
Description

account

address

The address that was not KYC-approved

constructor

Initializes the wrapper with underlying token and KYC registry

Parameters

Name
Type
Description

initialOwner

address

The address that will own the contract

underlying_

contract IERC20

The ERC20 token to wrap

kyc_

contract SimpleKycRegistry

The KYC registry contract

wrap

Wrap ERC20 into confidential ERC7984 balance (KYC-gated)

Reverts if caller or recipient is not KYC-approved.

Parameters

Name
Type
Description

to

address

Recipient of the confidential balance

amount

uint256

Cleartext ERC20 amount to wrap

unwrap

Request an unwrap from confidential to public ERC20 (KYC-gated)

Burns the confidential amount and emits a handle that must be publicly decrypted and finalized.

Parameters

Name
Type
Description

from

address

Address whose confidential balance is burned

to

address

Recipient of the public ERC20

amount

euint64

Encrypted amount (handle)

unwrap

Request an unwrap from confidential to public ERC20 via encrypted input (KYC-gated)

Convenience overload: converts external input to euint64 then calls the handle-based unwrap.

Parameters

Name
Type
Description

from

address

Address whose confidential balance is burned

to

address

Recipient of the public ERC20

encryptedAmount

externalEuint64

Encrypted amount input

inputProof

bytes

Proof for the encrypted input

Last updated