Skip to main content

ProgramAccount

Derive Macro ProgramAccount 

Source
#[derive(ProgramAccount)]
{
    // Attributes available to this derive:
    #[program_account]
    #[type_to_idl]
}
Expand description

Derives ProgramAccount for a struct.

This macro generates implementations for account-related traits and optionally AccountToIdl and TypeToIdl.

§Attributes

§#[program_account(skip_idl, program = <ty>, seeds = <ty>, discriminant = <expr>)] (item level attribute)

§Arguments

  • skip_idl (presence) - If present, skips generating IDL implementations for this account
  • program (optional Type) - Specifies the program that owns this account type. Defaults to StarFrameDeclaredProgram at root of your crate (Defined by the #[derive(StarFrameProgram)] macro)
  • seeds (optional Type) - Specifies the seed type used to generate PDAs for this account
  • discriminant (optional Expr) - Custom discriminant value for the account type, overriding the Anchor style sighash

§Usage

use star_frame::prelude::*;


#[zero_copy(pod)]
#[derive(ProgramAccount, Debug)]
#[program_account(seeds = MyAccountSeeds)]
pub struct MyAccount {
    pub data: u64,
}

#[derive(GetSeeds, Debug, Clone)]
pub struct MyAccountSeeds {
    pub key: Pubkey,
}