Implementing Account Constraints

Accounts & Data

Chapter 5: Implementing Account Constraints

Constraints ensure accounts meet specific conditions.

Constraints

  • Ownership: Verify account owner.

  • Initialization: Check if initialized.

Example

#[account(
    init,
    payer = signer,
    space = 8 + 32,
)]
pub new_account: Account<'info, MyAccount>,

Page Layout:

  • Header: Fixed top bar with "Solana Learn" logo, navigation, and profile icon.

  • Main Content:

    • Left Panel (50%): This text content.

    • Right Panel (50%): Code snippet with constraints.

  • Footer: Link to Anchor Constraints.

Visuals:

  • Code Snippet: Highlighted init, payer.

  • Table: init ("Creates account"), payer ("Pays for creation").

Interactivity:

  • Quiz: Match constraints to descriptions.

Last updated