3
 #[account(
        init,
        seeds = 
        [   
            b"config".as_ref(),
            mint.key().as_ref(),
        ],
        bump,
        payer = sender,
        space = 90
    )]
    pub freezing_config : Account<'info,FreezingConfig>,

What seeds should i add to make the account unique everty time for the same mint address?

can anyone share how can i close this account with a small snippet?

1
  • These are two separate questions. If you link me another question that you post I'll be happy to answer each question individually.
    – NHeinDev
    Commented Aug 10, 2022 at 14:08

1 Answer 1

7

Here is the "recommended" example to close an account from common sealevel-attacks, there are also examples of "insecure" and "secure" ways to close an account to review if you are interested:

https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/9-closing-accounts

#[program]
pub mod closing_accounts_recommended {
    use super::*;

    pub fn close(ctx: Context<Close>) -> ProgramResult {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Close<'info> {
    #[account(mut, close = destination)]
    account: Account<'info, Data>,
    #[account(mut)]
    destination: AccountInfo<'info>,
}

#[account]
pub struct Data {
    data: u64,
}
2
  • 1
    is there a generic way to close an account without having to define his corresponding struct Data? It would be really handy for situations where the struct of an account has changed and you want to get rid of old accounts with the "wrong" data structure.
    – Ander
    Commented Oct 18, 2022 at 6:19
  • How comes this approach doesn't need seeds or bump? I thought it was required when using PDA accounts. Commented Oct 18, 2022 at 11:33

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.