Category: Identity | Difficulty: Advanced | Chapters: Erc7984, Swaps | Concept: ERC7984 → ERC20 swap using public decryption + FHE.checkSignatures (KYC is public)
Swap a confidential ERC7984 token amount to a public ERC20 via public decryption finalization
Why this example
This example focuses on ERC7984 → ERC20 swap using public decryption + FHE.checkSignatures (KYC is public). It is designed to be self-contained and easy to run locally.
should revert swap if operator approval is missing
should revert when omitting allowTransient for the token
API Reference
Overview
Swap a confidential ERC7984 token amount to a public ERC20 via public decryption finalization
Developer Notes
Example for fhEVM Examples - OpenZeppelin Confidential Contracts
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
InvalidFinalization
Error thrown when finalization is called with an invalid amount handle
Parameters
Name
Type
Description
amount
euint64
The invalid encrypted amount handle
fromToken
The confidential ERC7984 token to swap from
toToken
The public ERC20 token to swap to
kyc
The KYC registry for compliance checks
constructor
Initializes the swap contract with token addresses and KYC registry
Parameters
Name
Type
Description
initialOwner
address
The address that will own the contract
fromToken_
contract IERC7984
The ERC7984 token to swap from
toToken_
contract IERC20
The ERC20 token to swap to
kyc_
contract SimpleKycRegistry
The KYC registry contract
swapConfidentialToERC20
Swap confidential token amount to public ERC20 (two-step: request + finalize)
Requires operator approval on the fromToken for this contract.
Parameters
Name
Type
Description
encryptedAmount
externalEuint64
Encrypted amount input (requested swap amount)
inputProof
bytes
Proof for the encrypted input Emits ConfidentialTransfer on the ERC7984 token; the transferred handle must be publicly decrypted off-chain, then finalized with finalizeSwap.