Skip to content
Nederlands

​How to confidentially transfer tokens from one token account to another

To confidentially transfer tokens from one token account to another, both the sender and recipient must have token accounts configured with the ConfidentialTransferAccount state and approved to use Confidential Balances. The sender’s token account must also have an available confidential balance to transfer from. To transfer tokens confidentially:
  1. Create three proofs client side: Equality Proof (CiphertextCommitmentEqualityProofData): Verifies that the new available balance ciphertext after the transfer matches its corresponding Pedersen commitment, ensuring the source account’s new available balance is correctly computed as new_balance = current_balance - transfer_amount. Ciphertext Validity Proof (BatchedGroupedCiphertext3HandlesValidityProofData): Verifies that the transfer amount ciphertexts are properly generated for all three parties (source, destination, and auditor), ensuring the transfer amount is correctly encrypted under each party’s public key. Range Proof (BatchedRangeProofU128Data): Verifies that the new available balance and transfer amount (split into low/high bits) are all non-negative and within a specified range.
  2. For each proof:
    • Invoke the ZK ElGamal proof program to verify the proof data.
    • Store the proof-specific metadata in a proof “context state” account to use in other instructions.
  3. Invoke the ConfidentialTransferInstruction::Transfer instruction, providing the proof context state accounts.
  4. Close the proof context state accounts to recover the SOL used to create them.
The following diagram shows the steps involved in transferring tokens from a sender’s token account to a recipient’s token account.
Transfer TokensTransfer Tokens

Transfer Tokens

​Required Instructions

To confidentially transfer tokens from one token account to another, you must:
  • Generate an equality proof, ciphertext validity proof, and range proof client-side
  • Invoke the Zk ElGamal proof program to verify the proofs and initialize the “context state” accounts
  • Invoke the ConfidentialTransferInstruction::Transfer instruction providing the three proof accounts.
  • Close the three proof accounts to recover rent.
The Rust example below generates the proofs with the spl-token-confidential-transfer-proof-generation crate, verifies each into a context state account through the ZK ElGamal Proof program, references the three accounts in the transfer instruction, and closes them afterward. The TypeScript example uses the getConfidentialTransferInstructionPlan helper from @solana-program/token-2022/confidential, which assembles the same proof accounts, transfer, and closes as a multi-transaction instruction plan.

​Example Code

The following example confidentially transfers tokens from one account to another. Both accounts must already be configured for Confidential Balances, and the sender must have an available confidential balance. Confidential Balances depends on the ZK ElGamal Proof program, which is enabled on mainnet and devnet. The Token-2022 program bundled with solana-test-validator is built without confidential-transfer support, so Deposit and the steps after it fail with InvalidInstructionData. Run the examples on devnet (the code’s default; get devnet SOL from the Solana faucet) or on a mainnet-forking local validator such as Surfpool. The payer is the wallet at ~/.config/solana/id.json. The example creates its own mint, a sender and a recipient account, and funds the sender’s available balance first, so there are no addresses to replace.

​Rust

​Typescript