6
  1. Does the below declaration mean to create a PDA account?
#[derive(Accounts)]
pub struct CreatePixel<'info> {
    #[account(init, payer=user, space=Pixel::LEN)]
    pub pixel: Account<'info, Pixel>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}
  1. Or must I use 'seeds' to create PDA a account? No matter the seeds' value, is even "" (empty) acceptable?
// Data validators
#[derive(Accounts)]
pub struct CreateCounter<'info> {
    #[account(mut)]
    authority: Signer<'info>,
    #[account(
        init,
        seeds = [],
        bump,
        payer = authority,
        space = 100
    )]
    counter: Account<'info, Counter>,
    system_program: Program<'info, System>,
}

1 Answer 1

6

Does bellow declare mean to create a PDA account?

pub struct CreatePixel<'info> {
   #[account(init, payer=user, space=Pixel::LEN)]
   pub pixel: Account<'info, Pixel>,
   #[account(mut)]
   pub user: Signer<'info>,
   pub system_program: Program<'info, System>,
}

No, the init constraint without seeds and bump doesn't create the PDA account. It will mark the account as a signer and expect you to provide the signature while calling the instruction.

or must I use 'seeds' to create PDA account? no matter the seeds value, even "" empty is acceptable?

This is correct! You must use both seeds and bump constraints to initialize a PDA account. Seed is a byte-array so empty array is also a valid seed.

1
  • Got it. Thanks very much. Jan 8 at 15:39

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.