1

I am writing a Solana Program using Anchor framework.

I can't seem to get rid of a signing error I'm having while testing.

Instruction Accounts validation:

#[derive(Accounts)]
pub struct InitializeAuction2<'info> {
    /// State of our auction program (up to you)
    #[account(
        init,
        payer = signer,
        space = 8 + BoyncAuction::AUCTION_SIZE, 
    )]
    pub state: Account<'info, BoyncAuction>,

    #[account(mut)]
    pub signer: Signer<'info>,

    system_program: Program<'info, System>,
    rent: Sysvar<'info, Rent>,
}

Instruction Handler:}

    pub fn initialize2(ctx: Context<InitializeAuction2>, app_idx: i64, amount: u64) -> Result<()> {
        msg!("[BoyncProgram] Initializing new Boync Auction State");
        let auction_state = &mut ctx.accounts.state;

        auction_state.end_auction_at = app_idx; // App index is UnixTimestamp
        auction_state.authority = ctx.accounts.signer.key().clone();

        auction_state.state = AuctionState::create();

        Ok(())
    }

Test:

const mint = /* previously created mint account */
const user1 = new anchor.web3.Keypair();
const uid = new anchor.BN(parseInt((Date.now() / 1000).toString()));
const uidBuffer = uid.toBuffer("le", 8);


let [auctionStatePubKey, auctionStateBump] =
  await anchor.web3.PublicKey.findProgramAddress(
    [
      Buffer.from("auction"),
      user1.toBuffer(),
      mint.toBuffer(),
      uidBuffer,
     ],
   program.programId
);

const tx1 = await program.methods
  .initialize2(uid, amount)
  .accounts({
    state: auctionStatePubKey,
    signer: user1.publicKey,
    systemProgram: anchor.web3.SystemProgram.programId,
    rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  })
  .signers([user1])
  .rpc();
...

I hope I did not miss anything. Please let me know if context is not enough. Anyway, I can't submit this program call transaction. It fails with:

     Error: Signature verification failed
      at Transaction.serialize (node_modules/@project-serum/anchor/node_modules/@solana/web3.js/src/transaction.ts:586:13)
      at Provider.send (node_modules/@project-serum/anchor/src/provider.ts:116:22)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:25:23)

I tried making signer: provider.wallet.publickey, no go.

Any help as well as why this happens is greatly appreciated.

1 Answer 1

2

It looks like you're using a PDA for the state account

let [auctionStatePubKey, auctionStateBump] =
  await anchor.web3.PublicKey.findProgramAddress(
    [
      Buffer.from("auction"),
      user1.toBuffer(),
      mint.toBuffer(),
      uidBuffer,
     ],
   program.programId
);

To init a PDA, you'll need to include seeds and bump to #[account(...)], and list out the seeds

#[account(
    init,
    seeds = [],   <---- list seeds here
    bump
    payer = signer,
    space = 8 + BoyncAuction::AUCTION_SIZE, 
)]
pub state: Account<'info, BoyncAuction>,

The pda-derivation test from anchor repo might be a good reference to figure out the syntax to use for your seeds:

https://github.com/coral-xyz/anchor/blob/master/tests/pda-derivation/programs/pda-derivation/src/lib.rs

1
  • Yup, that was the case. I was actually trying to track down another CPI error and forgot to add state as PDA for this particular case. Thanks! Commented Aug 11, 2022 at 5:50

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.