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.