3

I need to get all the transaction instructions from the Versioned transaction object. Any idea about this?

3
  • 2
    Update your answer to state what you're starting with. For instance, are you starting with a versioned transaction in wire format (ie. raw bytes) or do you have a VersionedTransaction object in JavaScript? Commented Jan 30, 2023 at 6:07
  • I just have the VersionTransaction Object and I need to fetch the instructions from that
    – Aslam
    Commented Jan 31, 2023 at 5:14
  • Is my answer below what you needed, @Aslam? If so, click that ‘accept’ checkmark, when you have a chance. Commented Nov 14 at 17:37

1 Answer 1

4

The instructions are available in the transaction's VersionedMessage, which you can access like this:

const compiledInstructions = transaction.message.compiledInstructions;

Each instruction is a record of the following type:

type MessageCompiledInstruction = {
  /**
   * Ordered indices into the transaction keys array
   * indicating which accounts to pass to the program
   */
  accountKeyIndexes: number[];
  /**
   * The program input data
   */
  data: Uint8Array;
  /**
   * Index into the transaction keys array indicating the
   * program account that executes this instruction
   */
  programIdIndex: number;
};
2
  • But how indexes work with versioned transactions? Indexes there might be bigger than transaction key array
    – RowanStone
    Commented Feb 4, 2023 at 17:22
  • 1
    @RowanStone can you provide an example transaction you're trying to deserialize? An explorer link (or just base64 bytes) would go a long way toward helping us see what you're seeing.
    – Jordan
    Commented Feb 7, 2023 at 1:53

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.