Token einzahlen

So werden Token auf das vertrauliche ausstehende Guthaben eingezahlt

Bevor Token vertraulich übertragen werden können, muss das öffentliche Token-Guthaben in ein vertrauliches Guthaben umgewandelt werden. Diese Umwandlung erfolgt in zwei Stufen:

  1. Vertrauliches ausstehendes Guthaben: Zunächst werden Token vom öffentlichen Guthaben auf ein „ausstehendes“ vertrauliches Guthaben „eingezahlt“.
  2. Vertrauliches verfügbares Guthaben: Das ausstehende Guthaben wird anschließend auf das verfügbare Guthaben „angewendet“, wodurch die Token für vertrauliche Übertragungen verfügbar werden.

Dieser Abschnitt erläutert die erste Stufe: das Einzahlen des öffentlichen Token-Guthabens auf das vertrauliche ausstehende Guthaben.

Das folgende Diagramm zeigt die Schritte zum Einzahlen von Token vom öffentlichen Guthaben auf das vertrauliche ausstehende Guthaben:

Deposit Tokens

Erforderliche Anweisung

Um ein öffentliches Guthaben in ein vertrauliches ausstehendes Guthaben umzuwandeln, rufen Sie die ConfidentialTransferInstruction::Deposit Anweisungen auf. Der maximale Betrag pro Einzahlungsanweisung ist auf 2^48 begrenzt.

Das spl_token_client-Crate stellt eine confidential_transfer_deposit-Methode bereit, die eine Transaktion mit der Deposit-Anweisung erstellt und sendet, wie im folgenden Beispiel gezeigt.

Beispielcode

Das folgende Beispiel zeigt, wie das öffentliche Token-Guthaben auf das vertrauliche ausstehende Guthaben eingezahlt wird.

Vertrauliche Übertragungen sind abhängig vom ZK ElGamal Proof-Programm, das im Mainnet und Devnet aktiviert ist. Ein Standard-solana-test-validator aktiviert es nicht, jedoch ein Mainnet-forkender lokaler Validatoren wie Surfpool schon. Führen Sie das Beispiel gegen eines davon aus (der Code verwendet Devnet) mit einem finanzierten Zahler, und ersetzen Sie die Platzhalter für Mint- und Konten-Adressen durch Ihre eigenen.

Rust

const ZK_PROOF_PROGRAM_ID: Pubkey =
solana_pubkey::pubkey!("ZkE1Gama1Proof11111111111111111111111111111");
fn main() -> Result<()> {
let rpc_client = RpcClient::new_with_commitment(
String::from("https://api.devnet.solana.com"),
CommitmentConfig::confirmed(),
);
// Owner = fee payer = token account owner. The setup below configures the
// account for confidential transfers (see "Create a Token Account").
let owner = load_keypair()?;
let amount: u64 = 100;
let decimals: u8 = 2;
// Setup: create a confidential token account with public tokens.
let (mint, token_account) = setup_deposit_account(&rpc_client, &owner, amount, decimals)?;
// Deposit moves tokens from the public balance into the pending confidential
// balance. No proof is required. The tokens land in the pending balance and
// must be applied (see "Apply Pending Balance") before they can be spent.
let deposit_ix = deposit(
&spl_token_2022::id(),
&token_account,
&mint,
amount,
decimals,
&owner.pubkey(),
&[&owner.pubkey()],
)?;
let blockhash = rpc_client.get_latest_blockhash()?;
let transaction =
Transaction::new_signed_with_payer(&[deposit_ix], Some(&owner.pubkey()), &[&owner], blockhash);
let signature = rpc_client.send_and_confirm_transaction(&transaction)?;
println!("Deposited {amount} tokens to the pending confidential balance: {signature}");
Ok(())
}

Typescript

const client = await createClient()
.use(signerFromFile(join(homedir(), ".config/solana/id.json")))
.use(
solanaRpc({
rpcUrl: "https://api.devnet.solana.com"
})
);
// The Solana CLI default keypair, used as fee payer, mint authority, and
// token account owner.
const owner = client.payer;
const amount = 100n;
const decimals = 2;
// Setup: create a confidential mint and token account with public tokens.
const mint = await createConfidentialMint(client, owner, decimals);
const token = await createConfidentialTokenAccount(client, owner, mint);
await mintPublicTokens(client, owner, mint, token, amount);
// Deposit moves public tokens into the pending confidential balance. No proof
// is required; the tokens must then be applied before they can be spent.
const depositInstruction = getConfidentialDepositInstruction({
token,
mint,
authority: owner,
amount,
decimals
});
const result = await client.sendTransaction([depositInstruction]);
console.log(
`Deposited ${amount} tokens to the pending confidential balance: ${result.context.signature}`
);

Is this page helpful?

Inhaltsverzeichnis

Seite bearbeiten
© 2026 Solana Foundation. Alle Rechte vorbehalten.