> ## Documentation Index
> Fetch the complete documentation index at: https://cofhe-docs.fhenix.zone/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> A public ERC-20 token with an encrypted balance next to it, in one contract

`ERC20Confidential` is an OpenZeppelin `ERC20` with a second, encrypted balance for every holder. Use it when your token must keep working with every ERC-20 integration and holders opt in to privacy by moving tokens into the encrypted balance.

## How it differs from FHERC20

Each holder has two balances in the same contract:

* **A public balance.** `balanceOf`, `transfer`, `approve`, `transferFrom`, `allowance`, and `totalSupply` are the standard OpenZeppelin functions and behave exactly as on any ERC-20.
* **A confidential balance.** An encrypted `euint64` handle that only the holder, and accounts the token grants access to, can decrypt. You read it with `confidentialBalanceOf` and move it with the `confidentialTransfer` family.

`shield` moves tokens from the public balance into the confidential one, and `unshield` plus `claimUnshielded` move them back.

On an [FHERC20](/cofhe/fhe-library/confidential-contracts/fherc20/overview) token, the ERC-20 surface is only an indicator and its transfers revert. Here it is real, so `balanceOfIsIndicator()` returns `false` and `indicatorTick()` returns `0`.

| | `ERC20Confidential` | `FHERC20` |
| - | - | - |
| Public balance | Real, standard ERC-20 | None. `balanceOf` returns an indicator |
| Confidential balance | Opt in with `shield` | Every balance |
| ERC-20 transfers | Work | Revert |
| Needs `ERC20ConfidentialLib` linked | Yes | No |

Pick `ERC20Confidential` for a new token that needs both modes. To add privacy to a token that is already deployed, use a [wrapper](/cofhe/fhe-library/confidential-contracts/fherc20/fherc20-wrapper) instead.

## A minimal token

`ERC20Confidential` takes a name, a symbol, and the decimals of the public balance:

```solidity DualToken.sol theme={null}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { ERC20Confidential } from "fhenix-confidential-contracts/contracts/ERC20Confidential/ERC20Confidential.sol";

contract DualToken is ERC20Confidential {
    constructor() ERC20Confidential("Dual Token", "DUAL", 18) {
        _mint(msg.sender, 1_000_000 ether);
    }
}
```

`_mint` is the OpenZeppelin function, so this mints public tokens. Holders call `shield` to make them confidential.

The constructor also deploys a small indicator token that wallets can track. See [how the two balances relate](/cofhe/fhe-library/confidential-contracts/dual-mode/dual-balance-model#the-indicator-token).

## Decimals and units

The confidential balance is a 64-bit integer with at most 6 decimals. `confidentialDecimals()` returns `6`, or the public decimals if those are lower. Every confidential unit is backed by a fixed number of public base units:

```text theme={null}
rate = 10 ** (decimals - confidentialDecimals)
```

For an 18-decimal token the rate is 10^12. Shielding `1 ether` credits `1_000_000` confidential units, and you pass confidential amounts in those units to transfers and `unshield`.

## Deploy it

`ERC20Confidential` and `ERC20ConfidentialUpgradeable` call into the external `ERC20ConfidentialLib`, so you must deploy that library and link it before you deploy the token. See [link the shared library](/cofhe/fhe-library/confidential-contracts/overview#link-the-shared-library). For the upgradeable variant, see [upgradeable tokens](/cofhe/fhe-library/confidential-contracts/upgradeable).

<Tip>
  Enable the Solidity optimizer. `DualToken` compiles to about 16 KB of bytecode with the optimizer off, and a token with a few extra functions grows quickly toward the 24 KB limit.
</Tip>

## Pages in this section

<CardGroup cols={2}>
  <Card title="How the two balances relate" icon="scale-balanced" href="/cofhe/fhe-library/confidential-contracts/dual-mode/dual-balance-model">
    The pool that backs confidential balances, total supply, and the indicator token.
  </Card>

  <Card title="Shield and unshield" icon="arrows-rotate" href="/cofhe/fhe-library/confidential-contracts/dual-mode/shield-unshield">
    Move tokens between the public and the confidential balance.
  </Card>

  <Card title="Confidential transfers and operators" icon="lock" href="/cofhe/fhe-library/confidential-contracts/dual-mode/confidential-operations">
    How encrypted transfers differ from FHERC20.
  </Card>

  <Card title="Extend ERC20Confidential" icon="puzzle-piece" href="/cofhe/fhe-library/confidential-contracts/dual-mode/extending">
    Freeze accounts, add a compliance observer, mint confidentially, or bring your own ledger.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.