Skip to content
Français

​How to apply pending balance to available 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 second stage: applying the pending balance to the available balance. When tokens are “deposited” from the public balance or when tokens are confidentially transferred from one token account to another, the tokens are initially added to the confidential pending balance. Before tokens can be used for confidential transfers, the pending balance must be “applied” to the available balance.
Apply Pending BalanceApply Pending Balance

Apply Pending Balance

The following diagram shows the steps involved in applying the pending balance to the available balance:
Apply Pending BalanceApply Pending Balance

Apply Pending Balance

​Required Instruction

To convert a pending balance to an available balance, invoke the ConfidentialTransferInstruction::ApplyPendingBalance instruction. The spl_token_client crate’s confidential_transfer_apply_pending_balance method builds and sends a transaction with the ApplyPendingBalance instruction. The examples below build the instruction directly instead.

​Example Code

The following example demonstrates how to apply the confidential pending balance to the confidential available 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 deposits tokens to the pending balance, so there are no addresses to replace.

​Rust

​Typescript