解包 Lamports 的作用是什么?
UnwrapLamports 将 SOL 从原生(已包装 SOL)token
account 中移出,以 lamport 的形式转入目标账户。您可以解包全部余额或指定数量,且 token
account 保持开启状态。
这比关闭已包装的 SOL 账户更为灵活:部分解包允许您提取部分 SOL,同时保持账户资金可供后续使用。
源码参考
账户
| 账户 | 描述 |
|---|---|
source | 可写。待解包的原生(已包装 SOL)token account。 |
destination | 可写。接收已解包的 lamport。 |
authority | 账户所有者或受委托方(或多签签名者)。 |
源账户必须是原生 token account;其他 token account 将返回
NonNativeNotSupported。受委托方最多可解包其被委托的数量。
如何解包 Lamports
省略 amount
可解包全部余额,或将其设置为解包指定数量的 lamport。本示例使用已配置的
@solana/kit
客户端——客户端设置请参阅 转移代币。
Unwrap wrapped SOL (Kit)
import { getUnwrapLamportsInstruction } from "@solana-program/token";// source: the native (wrapped SOL) token account to unwrap.// destination: address that receives the unwrapped lamports.// authority: a TransactionSigner (the account owner or a delegate).// Unwrap a specific number of lamports.const unwrapSome = getUnwrapLamportsInstruction({source,destination,authority,amount: 500_000_000n});// Or omit `amount` to unwrap the entire balance.const unwrapAll = getUnwrapLamportsInstruction({source,destination,authority});// Send whichever instruction you need.await client.sendTransaction([unwrapSome]);
对于多签授权方,请通过 multiSigners 传入联署人。
Is this page helpful?