Skip to main content
  1. 通过专用的 RPC 方法从索引器读取加密的私密 Solana 代币账户。
  2. 只有用户或用户授权的人可以用他们的查看密钥解密余额。
  3. 在私密余额变动后和转账前使用它。
  1. getBalance 返回公开的 SOL。getAccount 返回一个公开的代币账户。
  2. RPC 返回公开的余额。

开始使用

1

前提条件

The TypeScript examples require Node.js 24 or later, pnpm 11.18.0, and the Solana CLI.
Source: sdk-libs/ts
Add a Helius API key:
.env
The examples use the Solana CLI wallet as the payer by default. The payer must hold devnet SOL. See How to Get Devnet SOL.
2

导出查看标签

  • senderViewTagsenderAddress.confidentialViewTag(),发送者在机密环中的 Solana 公钥。索引器使用它返回匹配的加密输出。
3

从索引器获取交易输出

  • getShieldedTransactionsByTags 获取与 senderViewTag 相关的加密输出。
  • atSlot(depositTx.slot) 等待索引器在该插槽中有存款。
  • 索引器返回加密的输出数据。它不解密私密余额。
4

解密为私密余额

  • senderKeypair 提供发送者的查看密钥用于本地解密。
  • decryptToBalances 解密匹配的输出并返回发送者的私密余额。
  • balancesAfterDeposit.balance(SOL_MINT) 读取私密 SOL 余额。
请参阅 概念 了解所有者标记和私密 Solana 代币账户的工作原理。

完整代码示例

克隆并运行示例:
这些示例在 local/devnet 上使用机密环 这里

相关指导

存款

转账

取款

读取私密历史

Didn’t find what you were looking for?

Reach out! Telegram | E-Mail | Contact