0

I'm getting a Signature verification failed error from nowhere before this it was working 100% fine.

const UserStakeAccount = new PublicKey(stakeAccount);

        const { vaultAccount } = await stakeProgram.account.stakePool.fetch(
          stakePoolAccount
        ); const UserStakeAccount = new PublicKey(stakeAccount);

        const [programAuthority, bump_seed] =
          await PublicKey.findProgramAddress(
            [Buffer.from(anchor.utils.bytes.utf8.encode('authority'))],
            stakeProgram.programId
          );
        const { vaultAccount } = await stakeProgram.account.stakePool.fetch(
          stakePoolAccount
        );

 await stakeProgram.rpc.withdraw({
          accounts: {
            userStakeAccount: UserStakeAccount,
            receiverTokenAccount: userTokenAccount,
            vaultAccount: vaultAccount,
            vaultAuthority: programAuthority,
            stakePoolAccount: stakePoolAccount,
            authority: publicKey,
            systemProgram: SystemProgram.programId,
            tokenProgram: TOKEN_PROGRAM_ID,
          },
        });
2
  • 1
    Kindly provide more context. Full code snippets if any. Otherwise it's difficult to give an helpful answer
    – Ademola
    Commented Mar 30, 2023 at 11:41
  • @Ademola I've edit the question
    – Bunny
    Commented Mar 31, 2023 at 10:52

1 Answer 1

2

You're not specifying the signature your instruction requires. Any account marked with the #[account(signer)] attribute or that is of type Signer<'info> needs to sign for your instruction to work.

Anchor can tell from the IDL what signatures you should be passing in and thus throws that error knowing that you haven't passed in the required signature(s).

I can't tell the accounts that need to sign unless I see your on-chain Accounts struct, but call the method with this format:

await StakeProgram.methods
    .withdraw()
    .accounts({
        //Fill with the needed accounts as done above 
    })
    .signers([])
    .rpc();

The signers array argument should be populated so it contains the keypairs of your instructions's signers.

9
  • do I have to provide the signer of the user also?
    – Bunny
    Commented Apr 19, 2023 at 7:01
  • Usually no. The connected provider wallet signs every transaction by default in anchor
    – Ademola
    Commented Apr 19, 2023 at 8:43
  • I'm not creating any account in this transaction.
    – Bunny
    Commented Apr 27, 2023 at 12:09
  • Is the authority your anchor provider wallet(provider.publicKey)? It'll only sign your tx by default if that's the case. Otherwise if it's a separate account you created with Keypair.generate(), you have to explicitly sign by passing the keypair into the array in .signers([]).
    – Ademola
    Commented Apr 27, 2023 at 19:22
  • after brief debugging I've found that my PDA is deleted. how? I have token in it. how can I get my token?
    – Bunny
    Commented May 3, 2023 at 13:25

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.