3

Using connection.confirmTransaction getting the following error:

confirmTransaction error: Cannot assign to read only property '_nextClientSubscriptionId' of object '#<Connection>'
const blockdetails = await connection.getLatestBlockhash();
tx.lastValidBlockHeight = blockdetails.lastValidBlockHeight;
tx.recentBlockhash = blockdetails.blockhash;
tx.feePayer = payer.publicKey;
const signedTx = await payer.signTransaction(tx);
const sendOptions: SendOptions = {
  maxRetries: 3,
  preflightCommitment: "processed",
  skipPreflight: true,
};
const txnSignature = await connection.sendRawTransaction(
  signedTx.serialize(),
  sendOptions
;

const confirmStrategy: BlockheightBasedTransactionConfirmationStrategy = {
  signature: txnSignature,
  blockhash: blockdetails.blockhash,
  lastValidBlockHeight: blockdetails.lastValidBlockHeight,
};

const conf = await connection.confirmTransaction(
  confirmStrategy,
  "processed"
);
3
  • AFAIK confirmTransaction takes in the Tx Signature + commitment
    – Pratik.js
    Commented Jul 27, 2022 at 11:26
  • @Pratik.js it's part of the confirmStrategy , the old API got signature and commitment only.
    – Ohad Dahan
    Commented Jul 27, 2022 at 14:52
  • You're using Vue, aren't you @OhadDahan? Commented Jul 29, 2022 at 21:53

2 Answers 2

5

This is almost certainly because you're using Vue, and:

  • Your Connection object has undergone a reactive/readonly transformation
  • Connection._nextClientSubscriptionId is now a readonly ref

Without seeing more of your code, my only suggestion is to figure out where this transformation is happening and either:

5
  • Actually using React, not sure what suddenly caused this change in my Connection object. But I worked around it by creating another Connection just for running confirmTransaction. Not the cleanest solution but works :)
    – Ohad Dahan
    Commented Jul 30, 2022 at 16:24
  • 1
    Yeah, you need to take a look at where and how that original non-working Connection object is created and stored. I’m betting that there’s some code, somewhere, that’s modifying that instance. Commented Jul 31, 2022 at 5:46
  • OMG this happened to me on another repo now @steveluscher
    – Ohad Dahan
    Commented Aug 3, 2022 at 14:34
  • Find the commonality! Commented Aug 4, 2022 at 3:07
  • Yeah, will see who's the culprit , seriously annoying issue.
    – Ohad Dahan
    Commented Aug 4, 2022 at 7:22
3

Posting an updated answer as I ran into the same problem, but not using Vue.

In my case we are using Recoil for state management, which transforms objects to readonly. Those using Recoil for state management should add the dangerouslyAllowMutability: true option to all atoms of the connection instance or atoms that have a nested connection instance (i.e. Anchor's Program class).

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.