1

I'm parsing some information regarding transactions from JSON RPC API. However, I'm confused concerning innerInstructions and instructions (in transactions) fields.

Basically, I just want to know the type of transfer, the amount and from/to.

For example, if you look at this transaction signature in solscan.io in Transaction Actions field:

5Duc8t3dVWKBz48TwdSyJXaUSpeLQQPeDorEsxqokSAbvb3tdyoDPL8fp81udu8DgDMJSjvFPgUvwigbkYaxnuwk

From JSON RPC API, all information required are inside innerInstructions field. But in transactions field which contain instructions field I'm getting only the following:

instructions: [
  {
    accounts: [],
    data: LLMtf9,
    programId: ComputeBudget111111111111111111111111111111,
    stackHeight: None
  }, 
  {
    accounts: [...],
    data: 88nNHV4ezjuwf94ruuMVS,
    programId: GaaxVrdMh69Dhce9u4uSpdXD8L9J51SZ4x8vQywR6d7s,
    stackHeight:
    None
   }
], 
recentBlockhash: 5teZ8Af9VfDakJh8aQMzL7axv799ThAnRa38JnvAR2RF},
[...]
  • So does all transactions request provide the relevant information in innerTransactions only and instructions field from transactions can be ignored ? Is there any specific case ?

1 Answer 1

2

You need to consider both fields.

A transaction has a sequence of instructions, where each instruction has a program ID, accounts and data. That program freely determines how it interprets the data and how it uses the accounts.

One thing that program can do is call out to other programs, this is called Cross-Program invocation (CPI). When it does this, it will do the same thing - it'll pass data + accounts to a different program ID. These calls show as the innerInstructions of the transaction.

So a transaction could call directly to eg. the Orca program (which is used for a swap in your example transaction), and that would show as an instruction in the transaction. Or, as in your example transaction, it might call to a different program which then makes a CPI call to Orca, and that would show the Orca call as an inner instruction.

You need to consider the data in both to understand what has happened in the transaction.

2
  • Thank you for the great reply. However, how can I identify that the program make a CPI ? Visually now, I can easily see it but programmatically, I'm not sure where to look. I noticed that the program for the transaction is a BPF Upgradeable Loader, so I guess the program can be updated. But I don't know if it is relevant.
    – microchip
    Commented Jul 3 at 13:58
  • 1
    If there are innerInstructions then each of them will have an index, which is a top-level instruction, and then a list of inner instructions that top-level instruction is responsible for. The structure is documented here: solana.com/docs/rpc/json-structures#inner-instructions
    – Callum M
    Commented Jul 3 at 14:14

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.