3

I try to sign a text and I get this error.

const anchorWallet = useAnchorWallet();

const MEMO_PROGRAM_ADDRESS = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
const MEMO_PROGRAM_ID = new PublicKey(MEMO_PROGRAM_ADDRESS);

const onTestSign = async () => {
   if (!anchorWallet) return;

   const tx = new Transaction();
   tx.add(
      new TransactionInstruction({
         programId: MEMO_PROGRAM_ID,
         keys: [],
         data: Buffer.from("hello world", "utf8"),
      })
   );

   tx.feePayer = anchorWallet.publicKey;
   tx.recentBlockhash = Keypair.generate().publicKey.toString();

   await anchorWallet.signTransaction(tx);
};

Error

Again Above code works well on localhost, but when I test on the live server I got the above error.

Live: https://solana-web2-auth.vercel.app/

Thanks

1 Answer 1

1

You're not grabbing a valid blockhash:

tx.recentBlockhash = Keypair.generate().publicKey.toString();

Try replacing it with a recent blockhash:

let latestBlockhash = await connection.getLatestBlockhash('finalized');
tx.recentBlockhash = latestBlockhash.blockhash;
2
  • this solution does not work. why should i use blockhash? the transaction is not sent to the chain.. Also the codes work very well on localhost.
    – tolgaandx
    Commented Oct 26, 2022 at 17:00
  • @tolgaandx why are you using a transaction if you don't want it to go on the chain?
    – NHeinDev
    Commented Oct 27, 2022 at 20:34

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.