Skip to content
Русский

​How to deposit tokens to confidential pending balance

Before tokens can be transferred confidentially, the public token balance must be converted to a confidential balance. This conversion happens in two stages:
  1. Confidential Pending Balance: Initially, tokens are “deposited” from public balance to a “pending” confidential balance.
  2. Confidential Available Balance: The pending balance is then “applied” to the available balance, making the tokens available for confidential transfers.
This section explains the first stage: depositing public token balance to the confidential pending balance. The following diagram shows the steps involved in depositing tokens from the public balance to the confidential pending balance:
Deposit TokensDeposit Tokens

Deposit Tokens

​Required Instruction

To convert a public balance to a confidential pending balance, invoke the ConfidentialTransferInstruction::Deposit instruction. The maximum amount per deposit instruction is limited to 2^48. The spl_token_client crate’s confidential_transfer_deposit method builds and sends a transaction with the Deposit instruction. The examples below build the instruction directly instead.

​Example Code

The following example demonstrates how to deposit public token balance to confidential pending 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 and confidential token account and mints public tokens to it, so there are no addresses to replace.

​Rust

​Typescript