1

I have a code which is on NextsJs React code and runs when I run it with npm run dev, But when I build it with npm run build followed by pm2 restart rps I get this error:

WalletSendTransactionError: Blob.encode[recentBlockhash] requires (length 32) Uint8Array as src
    at el.sendTransaction (665.1ad8f2fdfae3f382.js:1:42460)
    at async 665.1ad8f2fdfae3f382.js:1:48390 el {_events: n, _eventsCount: 4, signTransaction: ƒ, signAllTransactions: ƒ, signMessage: ƒ}
(

My code is :

const { connected, publicKey, sendTransaction } = useWallet();

/* ... */

const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const dmlcoWallet = new PublicKey(/* <MyWalletPublicKey> */);

const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: publicKey,
    toPubkey: dmlcoWallet,
    lamports: LAMPORTS_PER_SOL * data.pay,
  }),
);
transaction.feePayer = publicKey ?? profile.value.walletPublicKey;

let recentHash = await connection.getLatestBlockhash("confirmed");
transaction.recentBlockhash = recentHash.blockhash;

const signature = await sendTransaction(transaction, connection, {
  preflightCommitment: "confirmed",
});

recentHash = await connection.getLatestBlockhash("confirmed");
// transaction.recentBlockhash = recentHash.blockhash;

await connection.confirmTransaction({
  blockhash: recentHash.blockhash,
  lastValidBlockHeight: recentHash.lastValidBlockHeight,
  signature: signature,
});

The code executes to this point: sendTransaction(...)

I run both debug & production on devnet.

4
  • 1
    I got the same issue today. It works when the code is not minimized / compressed for production. I've made a production build while ignoring minimization and it works. I know this isn't a solution but at least its isolating the issue
    – Danny
    Apr 18, 2023 at 23:05
  • Was also having this issue, been debugging it for a while, and it's randomly fixed. Did need to rebuild though!
    – Wooddyy
    Apr 19, 2023 at 0:04
  • @Danny Thanks for the solution, solved my problem, I know It's not a proper solution but you can post your comment as answer and I will update this issue whenever it gets fixed by the package developer team. Apr 19, 2023 at 7:40
  • 2
    I’m voting to close this question because the OP solved the issue without posting the solution as an answer. If you think the solution would be of use to someone else with the same problem, post a self-answer and accept your own answer! Dec 30, 2023 at 2:33

0