0

I was playing with counter program in program-example repo.

When run test, I got warning: Transaction references a signature that is unnecessary, only the fee payer and instruction signer accounts should sign a transaction., even though the contract method executed as expected.

The on-chain code is:

#[program]
pub mod counter_anchor {
    use super::*;
        ...
        
    pub fn increment(ctx: Context<Increment>) -> Result<()> {
        msg!(" call increment +  ...");        
        ctx.accounts.counter.count = ctx.accounts.counter.count.checked_add(1).unwrap();
        Ok(())
    }
    ....
}

    ...
#[derive(Accounts)]
pub struct Increment<'info> {
    #[account(mut)]
    pub counter: Account<'info, Counter>,
}

#[account]
#[derive(InitSpace)]
pub struct Counter {
    count: u64,
}

And my client js code is:

async function test_call_increase() {

  let tx = await program.methods
    .increment()
    .accounts({
      counter: counterKeypair.publicKey,
    })
    // .signers([payer.payer, counterKeypair])    
    .transaction();

    let txHash = await sendAndConfirmTransaction(
      provider.connection,
      tx,
      [wallet.payer, counterKeypair],  // <== Here, two signer, first one for pay gas.
      { skipPreflight: true }
      );

}

Also , in target/types/counter_anchor.ts , its isSigner is false.

    {
      "name": "increment",
      "accounts": [
        {
          "name": "counter",
          "isMut": true,
          "isSigner": false
        }
      ],
      "args": []
    },

AFAIK, I should let counter account to participate signing as to change its account data.

Why it say that counter shouldn't appear in signer list? How to fix it?

Thanks.

1
  • OK, I got it. Because this account was declared with ' #[account(init,...)]' macro. so this account's owner is my own program, though it isn't PDA. Commented Mar 12 at 8:40

1 Answer 1

0

I found the reason is: account was declared with ' #[account(init,...)]' macro. so this account's owner is my own program, though it isn't PDA.

But, as to program owned accounts(non-PDAs) and PDAs, which one should choose? I know when to choose PDAs, but don't know when to use program owned accounts(non-PDAs).

What's your opinion?

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.