closeAccount static method

TransactionInstruction closeAccount({
  1. required Pubkey account,
  2. required Pubkey destination,
  3. required Pubkey owner,
  4. List<Pubkey> signers = const [],
})

Close an account by transferring all its SOL to the destination account. Non-native accounts may only be closed if its token amount is zero.

Keys:

  • Single owner

  • [w] account - The account to close.

  • [w] destination - The destination account.

  • [s] owner - The account's owner.

  • Multisignature owner

  • [w] account - The account to close.

  • [w] destination - The destination account.

  • [] owner - The account's multisignature owner.

  • [s] signers - The signer accounts.

Implementation

static TransactionInstruction closeAccount({
  required final Pubkey account,
  required final Pubkey destination,
  required final Pubkey owner,
  final List<Pubkey> signers = const [],
}) {
  // * Single owner
  // 0. `[writable]` The account to close.
  // 1. `[writable]` The destination account.
  // 2. `[signer]` The account's owner.
  //
  // * Multisignature owner
  // 0. `[writable]` The account to close.
  // 1. `[writable]` The destination account.
  // 2. `[]` The account's multisignature owner.
  // 3. ..3+M `[signer]` M signer accounts.
  final List<AccountMeta> keys = [
    AccountMeta.writable(account),
    AccountMeta.writable(destination),
    AccountMeta(owner, isSigner: signers.isEmpty),
    for (final Pubkey signer in signers)
      AccountMeta.signer(signer),
  ];

  return _instance.createTransactionIntruction(
    TokenInstruction.closeAccount,
    keys: keys,
  );
}