Skip to content

PDA ConstraintSeeds error with generated js client #108

@SDPyle

Description

@SDPyle

I love what this project is doing, and I'm very grateful for it.

I'm having an issue with PDAs and the generated js client.

Simple modification to the template scaffold to use a seed from the instruction:

 #[program]
mod drp_test_scaffold {
    use super::*;

    pub fn create(ctx: Context<Create>, name: String, authority: Pubkey) -> Result<()> {
        let counter = &mut ctx.accounts.counter;
        counter.name = name;
        counter.authority = authority;
        counter.count = 0;
        Ok(())
    }
}

#[derive(Accounts)]
#[instruction(name: String)]
pub struct Create<'info> {
    #[account(
        init, 
        seeds = [name.as_bytes()],
        bump,
        payer = payer, space = 8 + Counter::INIT_SPACE
    )]
    pub counter: Account<'info, Counter>,
    #[account(mut)]
    pub payer: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
#[derive(InitSpace)]
pub struct Counter {
    #[max_len(50)]
    pub name: String,
    pub authority: Pubkey,
    pub count: u64,
}

Test:

  const client = createDefaultSolanaClient();
  const [authority] = await Promise.all([generateKeyPairSignerWithSol(client)]);

  const createIx = await getCreateInstructionAsync({
    name: 'test',
    authority: authority.address,
    payer: authority,
  });
  await pipe(
    await createDefaultTransaction(client, authority),
    (tx) => appendTransactionMessageInstruction(createIx, tx),
    (tx) => signAndSendTransaction(client, tx)
  );

This generates:

AnchorError caused by account: counter. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated.',
        'Program log: Left:',
        'Program log: ALMnbtV3pynYhVK3rPrVwA5B3pPMuHu2BQA1HXog5zjv',
        'Program log: Right:',
        'Program log: 8KqoXYYR9irXEi63X1Xm1qA2LcJf19ZeVnmzbDwB6zhA',

I'm relatively new to Solana development, so it's entirely possible that I'm missing something, but it seems like something isn't working as intended.

Thank you for your time and attention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions