0

We are attempting to add 8 instructions to a transaction and send it, but we are encountering an error indicating that it is too long to be processed. We are trying to perform a swap operation that involves two transactions. We would like to combine these into a single transaction. How can we achieve this?

Thank you for your assistance.

const legacyTransaction = new Transaction({
          blockhash: recentBlockhashForSwap.blockhash,
          lastValidBlockHeight: recentBlockhashForSwap.lastValidBlockHeight,
          feePayer: publicKey,
        });

legacyTransaction.add(...txs[0]);
legacyTransaction.instructions.push(...txs[1]);

We also tried with VersionedTransaction but we got unsuccessful in this one as well.

2 Answers 2

1

I don't think this is possible without Jito. Solana has a max transaction size of 1232 bytes (https://docs.solanalabs.com/proposals/versioned-transactions#problem).

Therefore if your instructions are larger than this, you will not be able to gurantee that they are on the same block without the use of a Jito, which is able to guarantee up to 5 transactions (note: not instructions) sequentially in the same block.

See: https://jito-labs.gitbook.io/mev/searcher-resources/json-rpc-api-reference

0

You can add an instruction using the add() method from Transaction

e.g

const transferInstruction = SystemProgram.transfer({
  fromPubkey: sender.publicKey,
  toPubkey: receiver.publicKey,
  lamports: transferAmount * LAMPORTS_PER_SOL, // Convert transferAmount to lamports
});
 
// simple memo ix
const memeInstruction = new TransactionInstruction({
    keys: [{ pubkey: fromKeypair.publicKey, isSigner: true, isWritable: true }],
    data: Buffer.from("Data to send in transaction", "utf-8"),
    programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
  })

// Add the transfer and SPL Memo instruction to a new transaction
const transaction = new Transaction().add(transferInstruction).add(memoInstruction);

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.