如何正确使用`close_account`函数以关闭关联的令牌帐户?
我正在尝试从程序内部关闭关联的令牌帐户(ATA)。 ATA属于该程序。我找到了一个称为colled_account
的函数,但是我还没有弄清楚如何正确使用它。我正在使用锚。
我程序的所需流量是:
- 将令牌从程序ATA发送给用户ATA(我已经成功完成了此操作)
- 关闭用于令牌的程序ATA,
这是colled_account 看起来像:
pub fn close_account<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, CloseAccount<'info>>,
) -> Result<()> {
let ix = spl_token::instruction::close_account(
&spl_token::ID,
ctx.accounts.account.key,
ctx.accounts.destination.key,
ctx.accounts.authority.key,
&[], // TODO: support multisig
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.destination.clone(),
ctx.accounts.authority.clone(),
],
ctx.signer_seeds,
)
.map_err(Into::into)
}
colleeaccount
结构如下:(
#[derive(Accounts)]
pub struct CloseAccount<'info> {
pub account: AccountInfo<'info>,
pub destination: AccountInfo<'info>,
pub authority: AccountInfo<'info>,
}
我假设)帐户是ATA,权威是我的程序 - 但是在这种情况下, destination 是什么?为什么关闭帐户需要一个目的地,我应该将哪个帐户用作目标帐户?
I am trying to close an Associated Token Account (ATA) from inside a program. The ATA belongs to the program. I found a function called close_account
, but I haven't figured out how to use it properly. I'm using Anchor.
The desired flow of my program is:
- Send a token from the program ATA to the user ATA (I've done this successfully)
- Close the program ATA that was used for the token
This is what the implementation of close_account
looks like:
pub fn close_account<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, CloseAccount<'info>>,
) -> Result<()> {
let ix = spl_token::instruction::close_account(
&spl_token::ID,
ctx.accounts.account.key,
ctx.accounts.destination.key,
ctx.accounts.authority.key,
&[], // TODO: support multisig
)?;
solana_program::program::invoke_signed(
&ix,
&[
ctx.accounts.account.clone(),
ctx.accounts.destination.clone(),
ctx.accounts.authority.clone(),
],
ctx.signer_seeds,
)
.map_err(Into::into)
}
The CloseAccount
struct looks as follows:
#[derive(Accounts)]
pub struct CloseAccount<'info> {
pub account: AccountInfo<'info>,
pub destination: AccountInfo<'info>,
pub authority: AccountInfo<'info>,
}
(I assume) the account is the ATA and the authority is my program - but what is the destination in this context? Why would closing an account need a destination and which account should I use as the destination account?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于令牌帐户与Solana中的任何其他帐户一样,它们必须具有足够的溶胶来满足最低余额要求。关闭帐户时,您必须将该溶胶发送到其他地方,因此“目的地”。最好的选择是使用仅用于SOL而不使用的钱包 / SOL帐户。
更多信息 https://spl.solana.com/token#closing-closing-closing-closing-closing-accounts
Since token accounts are like any other account in Solana, they must have enough SOL to cover the minimum balance requirement. When closing an account, you must send that SOL somewhere else, hence the "destination". The best option is to use a wallet / SOL account that is only used for SOL and nothing else.
More info at https://spl.solana.com/token#closing-accounts