2

I've got a program that is required to be signed by two signers. One signer is the account in my phantom wallet and the other is created in the code.

 const blockhash = await program.connection.getLatestBlockhash('finalized');

  const transaction = new Transaction({
    lastValidBlockHeight: blockhash.lastValidBlockHeight,
    blockhash: blockhash.blockhash,
    feePayer: wallet.publicKey
  });
  
  transaction.add(instruction);
  transaction.sign(keypair);


  const signed = await wallet.signTransaction(transaction);
  const signature = await program.connection.sendRawTransaction(signed.serialize());

  await program.connection.confirmTransaction({
    blockhash: blockhash.blockhash,
    lastValidBlockHeight: blockhash.lastValidBlockHeight,
    signature: signature
  }, 'max');

After the const signed line I get this error:

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0xbc4

and it doesn't go to the const signature line. Please help me what am I doing wrong here?

2 Answers 2

1
  • transaction.feePayer and transaction.recentBlockhash must be set before you call transaction.sign() or transaction.partialSign(), and the transaction cannot be changed afterwards. See https://solana-labs.github.io/solana-web3.js/classes/Transaction.html#sign

  • After setting feePayer and recentBlockhash, change transaction.sign(keypair) to transaction.partialSign(keypair), and you should be good to go

2
  • 1
    const transaction = new Transaction({ lastValidBlockHeight: blockhash.lastValidBlockHeight, blockhash: blockhash.blockhash, feePayer: wallet.publicKey }); this line is setting the feepayer and blockhash. is it right?
    – Discardo
    Commented Aug 19, 2022 at 8:18
  • yes i believe that would work
    – billy
    Commented Aug 19, 2022 at 14:57
1

Sorry, did you edit your question? I remember yesterday the error was Signature verification failed right? Now after resolving that, it's 0xbc4? Editing the question like that might make the past answers super confusing for viewers, not sure if we should resolve this in another question.

But anyway, 0xbc4 is 3012 in decimal and if you take a look at https://docs.rs/anchor-lang/latest/anchor_lang/error/enum.ErrorCode.html, that corresponds to AccountNotInitialized - The program expected this account to be already initialized. There's probably a bug in your program somewhere or you forgot to run another initialize instruction before this.

Edit: I presume you're using anchor, dont think anyone else would start with error codes that high

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.