Build

Integrating

What an application has to do to hold and move confidential balances, in the order it has to do it, and where the sharp edges are.

What has to be true

Confidential balances are not a library you drop in. They are a property of the mint, the token account and the cluster, and if any one of those three is wrong there is no client-side workaround. Check all three before you write code.

Token programToken-2022, not the original SPL token program
MintCreated with the confidential transfer extension. This is decided once, at creation.
Proof verificationSolana's native zk-ElGamal proof program, present on the cluster you are targeting
ClientDerives keys and builds proofs on the user device. Nothing secret reaches a server.
WalletSigns a deterministic message for key derivation, then signs the transactions

The mint constraint is the one that ends most integrations before they start. Token-2022 extensions live inside the mint account layout: the space for them is allocated and the extension is initialized before the mint itself is initialized. A mint that already exists cannot grow a new extension afterwards, and no amount of client work routes around it.

# mint creation, schematic
allocate mint account with space for:
    ConfidentialTransferMint            <- has to be in this list
initialize ConfidentialTransferMint
    authority                 = <may reconfigure some settings later>
    auto_approve_new_accounts = true | false
    auditor_elgamal_pubkey    = <optional, decided here>
initialize mint (decimals, mint authority)
The practical consequence
An existing SPL mint cannot become confidential. Either the issuer ships a Token-2022 mint with the extension from the beginning, or someone wraps the asset into a new mint, which means new liquidity, new addresses and a new set of trust assumptions. Do not design around upgrading a mint later. It is not a feature that is coming.

Configuring an account

A confidential token account is a normal Token-2022 account with the confidential transfer extension on it, and it takes two steps: allocate it with room for the extension, then configure it. The allocation is not the same as a plain token account. A plain account is a fixed, small layout. A confidential one additionally carries an ElGamal public key, the pending and available balance ciphertexts, the decryptable copy of the available balance, the pending credit counters and a set of flags.

That means more bytes and a higher rent-exempt minimum. Compute the size from the extension list using the token program's own helper rather than hardcoding a number you measured once: the layout belongs to the token program and is not yours to pin.

# once per user, per mint
create associated token account (Token-2022)
    space    = account_size_for([ConfidentialTransferAccount, ...])
    lamports = rent_exempt(space)       <- larger than a plain token account

ConfigureAccount
    elgamal_pubkey              = <derived on the client, see below>
    decryptable_zero_balance    = <symmetric encryption of 0>
    max_pending_balance_credits = <bounded, see failure modes>
    proof                       = <you hold the matching secret key>

[ApproveAccount]    # only when the mint does not auto approve

Two details to build into onboarding. Configuration carries a proof that you hold the secret key for the ElGamal public key you are registering, so the wallet has to be connected and able to sign here, not later. And if the mint was created without automatic approval, a configured account cannot receive confidential credits until the mint's authority approves it, on their schedule rather than yours. Make that a visible state rather than a silently failing deposit.

Deriving the keys

There are two secrets per account and both are derived on the device. The ElGamal keypair over curve25519 is what the balance ciphertexts and the proofs are about. The second is a symmetric key used for the decryptable available balance, a separate encryption of the same number that exists purely so a wallet can read its own balance immediately: recovering a 64-bit amount from an ElGamal ciphertext alone means a discrete log search, which is fine for a program verifying arithmetic and miserable for a user interface.

Both come from a wallet signature over a fixed message. Ed25519 signing in Solana wallets is deterministic for a given key and message, so the same wallet reproduces the same keys on any device, with no separate backup to store and nothing to escrow. Bind the message to the account so one wallet produces different keys per account, and domain-separate it so a signature meant for this cannot be replayed into something else.

sig     = wallet.signMessage(DOMAIN || mint || token_account)
seed    = hash(sig)
elgamal = elgamal_keypair_from(seed, "balance")
symkey  = symmetric_key_from(seed, "decryptable-balance")

# never leaves the device, never sent to a server, and recoverable
# from nothing except the wallet seed itself

The message and its binding are part of your protocol surface. If you ship a wallet abstraction layer, or quietly change the domain string in a refactor, every existing user derives a different ElGamal key and finds a balance they can no longer read. Version the message and keep the old derivation available. More on recovery and viewing keys in keys and disclosure.

The first run order

Each step below is a separate on-chain action and the order is not negotiable. The one that surprises people is the last: value arriving in a confidential account lands in a pending balance and is not spendable until it is applied to the available balance.

1  create account         (Token-2022, space includes the extension)
2  ConfigureAccount      (elgamal pubkey, decryptable zero, credit cap)
3  Deposit               (public balance -> pending confidential balance)
4  ApplyPendingBalance   (pending -> available, new decryptable balance)
5  Transfer / Withdraw   (spends the available balance, with proofs)
  • Deposit moves value from the public side of the same account to the confidential side. No new account, no counterparty, no bridge.
  • Apply takes the pending ciphertext into the available one. The client supplies the new decryptable balance and the credit counter it believes it is applying, so the program can reject a stale apply built against an older view of the account.
  • Withdraw is the reverse of deposit, runs against the available balance, and so carries proofs and the same budget concerns as a transfer.
Apply is not an advanced action
Every incoming credit, whether a deposit the user made or a transfer someone else sent, arrives in pending and needs an apply. A wallet that hides this behind a menu produces users who think their money vanished. Surface the pending amount and offer the apply in the same place.

Proofs and budget

A confidential transfer carries more than one zero-knowledge proof: that the amount was re-encrypted consistently under the sender, receiver and auditor keys, that the sender's new balance follows from the old one by the ciphertext arithmetic the program can check, and that every amount involved is in range so nothing wrapped around. All of them are built on the client, from the sender's secret, before the transaction exists.

The constraint that shapes your whole integration is size. Solana transactions have a hard byte limit and these proofs are large, so a range proof plus a transfer instruction plus signatures does not reliably fit in one transaction. The proof program is designed for this: a verification can be submitted on its own and its result written into a proof context account, which the token instruction then points at instead of carrying the proof inline. Some proofs can also be split across instructions. Either way the user signs more than once.

tx A   ComputeBudget.setComputeUnitLimit(...)
       verify range proof            -> writes a proof context account

tx B   ComputeBudget.setComputeUnitLimit(...)
       verify the remaining proofs   -> writes proof context accounts

tx C   ComputeBudget.setComputeUnitLimit(...)
       confidential transfer         -> reads those context accounts
       close context state x N       -> returns the rent to the payer

How the proofs group into transactions depends on their size and on what else the transaction is carrying, so measure it on the cluster you ship to rather than copying a grouping from a document. Two things follow from the multi-transaction shape. Partial failure is normal, so the client has to be resumable: on start, look for context accounts this user already opened, reuse them or close them, and never assume a clean slate.

Proof verification is also compute heavy. The default per-instruction compute allowance is not enough, so an explicit compute unit limit is effectively mandatory on every one of these transactions, and an otherwise correct transfer will fail without it. Set the limit from measurement with headroom, and consider a priority fee, because these transactions are both large and expensive to land.

What an indexer sees

If you run an explorer, a tax tool or an accounting pipeline, be exact about what changed. The transaction is an ordinary Solana transaction: signature, slot, fee payer, instruction list, every account it touched. What is gone is the number, and only the number.

Still public
Both addresses, the mint, the token program, the slot and its timestamp, the fee and who paid it, and the plain fact that a transfer happened. Hiding amounts does not hide the graph.
  • A deposit reads as the public side of an account going down with no matching destination amount anywhere.
  • A confidential transfer shows both parties and no amount at all. The ciphertext sits in account data as opaque bytes.
  • The pre and post token balance fields an indexer normally reads describe the public side only. Your amount extraction will return zero or nothing, and zero is not the same as nothing: do not record a confidential transfer as a zero-value transfer.
  • Holder reports, supply-weighted analytics and balance gating stop working for these accounts. If an application needs a figure, the holder has to supply it through a viewing key.

Testing and failures

Test against devnet with the real proof program before you trust anything. A local validator is faster to iterate on, but confirm the proof program is actually available there and do not assume parity between clusters. You cannot borrow a mainnet mint for fixtures either, so create your own Token-2022 mint with the extension as part of test setup. Use at least two accounts under different keys, because several failures only appear on the receiving side, and deliberately kill the client between the proof transaction and the transfer transaction to prove the resume path works.

Transfer rejectedThe balance arrived but is still pending. Apply it first. This is the single most common report and it is not a bug.
Credits rejectedThe pending credit counter hit the maximum set on the account. An apply resets it. Choose that cap deliberately: high means heavier applies, low means a busy account blocks sooner.
Context in useA previous run left a proof context account open. Find it and reuse or close it. The rent stays locked until you do.
Budget exceededNo explicit compute unit limit, or one set too low for proof verification.
Transaction too largeProofs were carried inline. Move the verification into context accounts, or split it.
Balance displays wrongThe decryptable copy is out of step with the ciphertext, usually a client that applied without updating it. Resync from the on-chain ciphertext, never from local storage.
Different keys per deviceThe signing message or its binding changed. Treat the domain string as versioned protocol surface.

None of these are exotic. They are what a first integration hits in its first afternoon, and each one is a state your interface can name instead of a generic failure. The FAQ covers what users ask once it is in front of them.