In Anchor 0.29 I was manually closing out accounts in my contract like this.

let item_account_info = ctx.accounts.item.to_account_info();
let mut data = item_account_info.try_borrow_mut_data()?;
for byte in data.deref_mut().iter_mut() {
    *byte = 0;
let item_dst: &mut [u8] = &mut data;
let mut item_cursor = Cursor::new(item_dst);

Now I upgraded to 0.30, this is no longer possible so I'm trying to find some documentation on what is the most secure way to close an account within the program.

1 Answer 1


I was able to solve this by using the recommended method of passing the close attribute.

#[account(mut, close = destination)]


However, I'm still wondering if there are still other secure ways to close an account inline in program contract without passing the attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.