關閉帳戶指令
關閉一個代幣帳戶,並將其剩餘的 SOL 租金轉移到目標帳戶。該代幣帳戶必須為零餘額,除非它是原生的 SOL 帳戶。
在我們關閉任何代幣帳戶之前,我們需要已經完成以下操作:
初始化一個
Mint帳戶初始化一個
Token帳戶或一個沒有任何代幣的Associated Token帳戶。
以下是對 close_account() 指令的 CPI 的樣子:
rust
close_account(
CpiContext::new(
ctx.accounts.token_program.to_account_info(),
CloseAccount {
account: ctx.accounts.token_account.to_account_info(),
destination: ctx.accounts.authority.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
},
),
)?;