2

i'm getting a weird signer error when running my tests;

Error: Signature verification failed.
Missing signature for public key [`6jAudYFBbfQS59oPNjYcMkqr9MqBf312T7oP6WSYRjsg`].

In this case, 6jAudYFBbfQS59oPNjYcMkqr9MqBf312T7oP6WSYRjsg is the state object's pubkey.

Here's the test code:

const state = anchor.web3.Keypair.generate()
await program.rpc.stake(
      stakePDABump,
      beefAccountBump,
      new anchor.BN(5_000),
      {
        accounts: {
          tokenProgram: TOKEN_PROGRAM_ID,
          stakeMint: stakeMintAddress,
          state: state.publicKey, // here
          stakeMintAuthority: stakePDA,
          programBeefTokenAccount: beefAccountPDA,
          userStakeTokenAccount: user.stakeTokenAccount,
          userBeefTokenAccount: user.beefTokenAccount,
          beefMint: beefMintAddress,
          userBeefTokenAccountAuthority: user.wallet,
        }
      },
    );

Here's the instruction:

#[derive(Accounts)]
pub struct CreateBeefTokenAccount<'info> {
    #[account(
        init,
        payer = payer,
        seeds = [ BEEF_MINT_ADDRESS.parse::<Pubkey>().unwrap().as_ref() ],
        bump,
        token::mint = beef_mint,
        token::authority = program_beef_token_account,
    )]
    pub program_beef_token_account: Account<'info, TokenAccount>,
    #[account(
        address = BEEF_MINT_ADDRESS.parse::<Pubkey>().unwrap(),
    )]
    pub beef_mint: Account<'info, Mint>,
    #[account(mut)]
    pub payer: Signer<'info>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub rent: Sysvar<'info, Rent>,
    #[account(init, payer = payer, space = 8+State::MAXIMUM_SIZE)]
    pub state: Account<'info, State>,
}

1 Answer 1

2

Looks like your state should be a PDA so that your program can sign for it.

This would like smth like this:

#[account(  
        init,
        seeds = [b"state".as_ref()],
        bump,
        space = 8,
        payer = signer,
    )]

and in js you can then get the PDA like this:

const state = await PublicKey.findProgramAddress(
  [Buffer.from("state")],
  program.programId
);

If you want to create the key yourself you need to sign for it Which would look something like this:

const transaction = await program.methods
    .doSmth()
    .accounts({
      ...
    })
    .signers([state])
    .transaction();

  console.log("transaction", transaction);

  const txSig = await sendTransaction(transaction, connection,{
    signers: [state],
    skipPreflight: true
  } );
0

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.