0

Hello there is a problem with the txHash, it tells me that the signature is invalid can you help me please :

#[derive(Accounts)]
pub struct Deposit<'info> {
    #[account(
        init_if_needed, 
        payer=buyer,
        space = 4 + 8 + 8 + 8 + 8 + 8 + 32
    )]
    pub claimer: Account<'info, Claimer>, //this turns to be a signer??

    #[account(mut)]
    pub master: Account<'info, Master>,

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

    #[account(mut)]
    pub referal: Account<'info, Claimer>,

    pub system_program: Program<'info, System>,
}

And

        const claimer = await PublicKey.createWithSeed(
          wallet.publicKey, "claimer", PROGRAM_ID
        );
        const txHash = await program.methods.deposit(amount).accounts({
            claimer: claimer,
            master: masterAddress,
            buyer: wallet.publicKey,
            referal: new PublicKey("2MZY3b42NzbRjGyuALnkKJJ3NeFk2otXrMtzb9dBCQ7i"),
            systemProgram: SystemProgram.programId,
        })
        .rpc();

        await confirmTx(txHash, connection);


/////////
export const confirmTx = async (txHash, connection) => {
  const blockhashInfo = await connection.getLatestBlockhash();
  await connection.confirmTransaction({
    blockhash: blockhashInfo.blockhash,
    lastValidBlockHeight: blockhashInfo.lastValidBlockHeight,
    signature: txHash,
  });
};

the error im getting now is: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: Cross-program invocation with unauthorized signer or writable account

const deposit = async (amount) => {
    const [pda] = PublicKey.findProgramAddressSync(
      [wallet.publicKey.toBuffer(), Buffer.from("claimer")],
      PROGRAM_ID
    );
    const txHash = await program.methods.deposit(new BN(100000)).accounts({
        claimer: pda,
        master: masterAddress,
        buyer: wallet.publicKey,
        referal: new PublicKey("2MZY3b42NzbRjGyuALnkKJJ3NeFk2otXrMtzb9dBCQ7i"),
        systemProgram: SystemProgram.programId,
    })
    .rpc();

    await confirmTx(txHash, connection);
}

enter image description here

1 Answer 1

0

The error might be due to how you're deriving the PDA for the claim account.

try this instead:

  const [pda] = PublicKey.findProgramAddressSync(
    [wallet.publicKey.toBuffer(), Buffer.from("claimer")],
    PROGRAM_ID
  )
1
  • the error im getting now is: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: Cross-program invocation with unauthorized signer or writable account
    – yakito
    Jan 2 at 5:28

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.