トークンの入金

機密保留残高へのトークン預け入れ方法

トークンを機密転送するには、まず公開トークン残高を機密残高に変換する必要があります。この変換は2つの段階で行われます:

  1. 機密保留残高:最初に、トークンは公開残高から「保留中」の機密残高へ「預け入れ」られます。
  2. 機密利用可能残高:次に、保留残高が利用可能残高へ「適用」され、トークンが機密転送に使用できる状態になります。

このセクションでは、第1段階である公開トークン残高を機密保留残高へ預け入れる手順を説明します。

以下の図は、公開残高から機密保留残高へトークンを預け入れる際の手順を示しています:

Deposit Tokens

必要なinstruction

公開残高を機密保留残高に変換するには、 ConfidentialTransferInstruction::Deposit instructionを呼び出します。預け入れinstructionあたりの 最大金額 は2^48に制限されています。

spl_token_client クレートは、以下の例に示すように、Deposit instructionを含むトランザクションをビルドして送信する confidential_transfer_deposit メソッドを提供しています。

サンプルコード

以下の例では、公開トークン残高を機密保留残高へ預け入れる方法を示します。

機密転送はZK ElGamal Proofプログラムに依存しており、メインネットおよびデブネットで有効になっています。標準の solana-test-validator ではこれが有効になっていませんが、Surfpool のようなメインネットフォーキング対応のローカルvalidatorでは有効です。資金が入ったペイヤーを使用して、これらのいずれか(コードはデブネットを使用)に対してサンプルを実行し、プレースホルダーのミントアドレスとアカウントアドレスを自分のものに置き換えてください。

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?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。