3

If an account has been closed with the following anchor context:

#[account(
        mut,
        close = user,
        seeds = [
            SEED_SCHEMA.as_bytes(),
            &user.key().as_ref(),              
        ],
        bump
    )]
    pub account: Box<Account<'info, Account>>,

Can it be "repoened" again, if invoked with init and the same seeds?

Or is it not actually closed and need to invoke it with init_if_needed?

Trying to call function which in its context includes the initialisation for the above account gives me account already exists error, which I did not expect and am not sure how to solve it.

1
  • 1
    You can reuse the account, a tx with init and the same seeds will simply create the account again.
    – Whiteseal
    Commented Aug 16, 2023 at 19:05

1 Answer 1

3

The close attribute in anchor removes all lamports (SOL) from the account which basically frees/deletes the account.

After an account is closed, you should be able to init it as if it was never created before.

I've recreated your account and wrote a small test that initializes and then closes it. You can load the code linked below in Solana Playground to test it out, You can re-run the test over and over again and it won't return account already exists.

https://gist.github.com/serbangv/75709c3a044d2a89f9b1121e89201ba2

So in your case, either the account was never successfully closed or it's returning the error about a different account you're initializing in that instruction.

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.