Overview
FHERC20’s core functionality revolves around maintaining complete confidentiality for token balances and transfers while still enabling all the operations users expect from a token. This page explores the fundamental features that make FHERC20 work.Encrypted Balances
Storage Structure
FHERC20 maintains two parallel balance systems:Confidential Balances
Type:
euint64Real token balances encrypted using FHE. Only accessible with proper permissions, operations performed entirely on encrypted data.Indicator Balances
Type:
uint16Non-confidential activity indicators (0-9999) that provide visual feedback in wallets without revealing actual amounts.Balance Encryption
When tokens are minted or transferred, the amounts are always encrypted:The
euint64 type can store values up to 2^64 - 1, which is 18,446,744,073,709,551,615. For tokens with 6 decimals (recommended), this is equivalent to about 18.4 trillion tokens with full precision.Total Supply
Like balances, total supply is maintained in both confidential and indicated forms:Querying Total Supply
Confidential Transfers
FHERC20 provides multiple transfer functions to handle different scenarios.Basic Transfer
The fundamental transfer operation moves encrypted tokens from the caller to a recipient:Transfer Implementation
The internal_transfer function handles the actual movement:
The Update Function
The_update function is the core of all balance changes. It uses FHESafeMath for overflow/underflow protection on encrypted values:
Balance Queries
Confidential Balance
Returns the encrypted balance for an account:euint64 is still encrypted! You cannot read its value directly. To use it:
Indicator Balance
Returns the non-confidential indicator value:Balance Of Is Indicator
Returnstrue, signalling that balanceOf returns an indicator, not a real balance:
Access Control for Balances
As shown in the_update function above, access control is managed inline as part of each balance update:
- ✅ Users can access their own balances
- ✅ The contract can perform operations on balances
- ✅ Transfer participants (sender, receiver, and caller) can see the transferred amount
- ✅ Total supply is only accessible by the contract
Learn more about FHE access control in the Access Control guide.
Minting and Burning
Minting New Tokens
Burning Tokens
Amount Disclosure
FHERC20 includes optional disclosure functions for transparency when needed. Accounts with access to an encrypted amount can voluntarily reveal it on-chain.Requesting Disclosure
Completing Disclosure
The Indicator System in Detail
Indicator Values
Indicators range from0 to 9999, representing values from 0.0000 to 0.9999:
Indicator Lifecycle
1
Initial State
New accounts start with an indicator of
0.2
First Interaction
Upon first transfer (sent or received), the indicator initializes to
7984 (0.7984), referencing the ERC-7984 standard.3
Receive Transaction
Each time tokens are received, the indicator increases by
1 (0.0001).4
Send Transaction
Each time tokens are sent, the indicator decreases by
1 (0.0001).5
Wrapping
When the indicator reaches
9999, it wraps back to 0.Indicator Functions
Indicator Tick
TheindicatorTick is the amount reported in Transfer events and is calculated during contract construction:
_indicatorTick = 10^2 = 100- This represents 0.0001 tokens
Resetting Indicators
Users can reset their indicator to zero for privacy:Errors
FHERC20 defines the following custom errors:Events
FHERC20 emits standard ERC20 events with indicator values, plus confidential-specific events:The
Transfer event doesn’t reveal the actual transfer amount—only that a transfer occurred. The value field always contains indicatorTick to maintain ERC20 compatibility while preserving privacy.ERC20 Incompatible Functions
For privacy reasons, several standard ERC20 functions intentionally revert:confidentialTransfer()instead oftransfer()setOperator()instead ofapprove()confidentialTransferFrom()instead oftransferFrom()
Complete Example
Here’s a full example showing core FHERC20 features:Related Topics
- Learn about Operators for delegated transfers
- Explore Transfer Callbacks for safe transfers
- Understand Access Control for FHE permissions