Instruction đóng Account
Đóng token account và chuyển phí thuê còn lại của nó đến account đích. Token account phải có số dư bằng không trừ khi đó là native SOL account.
Trước khi chúng ta có thể đóng bất kỳ token account nào, chúng ta sẽ cần phải có:
- Account
Mint
đã khởi tạo - Account
Token
hoặc accountAssociated Token
không có token nào bên trong.
Instruction thô
Bằng cách chỉ sử dụng instruction "thô" mà không có bất kỳ abstraction nào, đây là cách đóng account sẽ trông như thế nào:
// Delegate an ATA
const closeAccountInstruction = createCloseAccountInstruction(
tokenAccount // account
keypair.publickey // destination
keypair.publickey // authority
);
const transaction = new Transaction().add(closeAccountInstruction);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log(`Token accounts closed! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
Instruction được trừu tượng hóa
Đây là cách các instruction tương tự sẽ trông như thế nào được trừu tượng hóa với instruction closeAccount()
:
let tx = await closeAccount(
connection,
keypair,
ata.address, // token Account
keypair.publicKey, // destination
keypair.publicKey, // authority
);
console.log(`Succesfully Closed!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)