1

Could someone clarify whether #[account(...)] used to apply constraints is completely different from #[account] used to specify the structure representing an account, or if they are related?

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(init, payer = signer, space = 8 + 8)]
    pub new_account: Account<'info, NewAccount>,
    #[account(mut)]
    pub signer: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
pub struct NewAccount {
    data: u64
}

Related pages from anchor-lang below:

https://docs.rs/anchor-lang/latest/anchor_lang/attr.account.html

https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html

1 Answer 1

1

Both of these have different jobs to do #[account] is used to represent an on-chain data struct and implement's a bunch of functions on it for serialization and deserialization.

#[account(...)] on the other hand is used for validations + a bunch of stuff/attributes like init,mut,close, constraint in the derive macro struct where all the accounts for instructions are added.

I don't have a deep dive knowledge this answer is based of my experience using anchor ;)

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.