2

From solana web3.js, it looks like it only shows 1 level deep of CPI.

How would I get inner ix 2 in this example:

tx:
  ix1:
    inner ix1:
      inner ix2:
  ix2:
    ...
  type ConfirmedTransactionMeta = {
    ...
    /** An array of cross program invoked instructions */
    innerInstructions?: CompiledInnerInstruction[] | null;
    ...
  };
    
  type CompiledInnerInstruction = {
    index: number;
    instructions: CompiledInstruction[];
  };
  
  type CompiledInstruction = {
    /** Index into the transaction keys array indicating the program account that executes this instruction */
    programIdIndex: number;
    /** Ordered indices into the transaction keys array indicating which accounts to pass to the program */
    accounts: number[];
    /** The program input data encoded as base 58 */
    data: string;
  };

1 Answer 1

1

Take a look at how the innerInstructions are returned from this example https://docs.solana.com/developing/clients/jsonrpc-api#notification-format-1

So you're very close! The index in CompiledInnerInstruction gives the index of the instruction in the top-level transaction, so to get inner ix 2, which is the second inner instruction in the first top-level instruction, you'd look at innerInstructions[0].instructions[1], and make sure that innerInstructions[0].index === 0.

2
  • But what about instructions with depth greater than 2?
    – Ozymandias
    Commented Feb 27 at 7:37
  • 1
    Everything is flattened, so the depth makes no difference
    – Jon C
    Commented Feb 27 at 11:33

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.