I want to Modify the compute unit for Versioned Transactions but there are some issue with that.
Before i Have used it for legacy transaction but now when i want to add new compute unit size to TransactionV0 it doesn't do that like before.
General Snippet codes for addComputeUnit, Create and Send v0 transaction:
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
units: 1000000 });
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1 });
const instruction = [
await program.methods.breedBee(false)
.accounts({list of accounts})
.signers([ list of signers])
.instruction()
]
const messageV0 = new TransactionMessage({
payerKey: staging_wallet.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: instruction
}).compileToV0Message([lookupTable]);
const transactionV0 = new VersionedTransaction(messageV0);
transactionV0.add(modifyComputeUnits); transactionV0.add(addPriorityFee);
❌ Property 'add' does not exist on type 'VersionedTransaction'.
So I changed .instruction() to .transaction() and then wanted to add modifyComputeUnits by this way:
const instruction = await program.methods.breedBee(false)
.accounts({list of accounts})
.signers([ list of signers])
.transaction()
instruction.add(modifyComputeUnits)
instruction.add(addPriorityFee)
instruction.recentBlockhash = blockhash
instruction.feePayer = staging_wallet.publicKey
with this approach I faced with another error while passing instruction into TransactionMessage:
const messageV0 = new TransactionMessage({
payerKey: staging_wallet.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: instruction
}).compileToV0Message([lookupTable]);
❌ the error:
TypeError: instructions is not iterable
TypeError: Cannot read properties of undefined (reading 'header')
so it can't compile TransactionMessage.