3

I'd like to create a parser of transactions to play around with solana web3.

I've seen that VersionedTransaction contains message & signatures.

The MessageV0 contains a bunch of publicKeys inside the "staticAccountKeys" as well as addressTableLookups and compiledInstructions.

I'm finding it hard to reconstruct what a tx is doing based ont he instructions.

From my "reverse engineering" stuff i've noticed that if an instruction looks like this:

{
programIdIndex: 17,
accountKeyIndexes: [1,2],
data: Uint8Array(8) [
  3, 59, 0, 0,
  0,  0,  0, 0
]

} then it means that the instruction is meant for the program having pubkey equal to staticAccountKeys[17].

This program will receive the 8 bytes 3,59,0,0,0,0,0,0. but what i dont understand is accountKeyIndexes (in this case 1,2). What are these suppoused to represent?

1 Answer 1

2

Transactions are serialized in such a way to minimize size. One of the ways this happens is by minimizing re-use of accounts. This means if we have an instruction that takes the accounts ABC and DEF, we don't attach these to the instruction directly. Instead, we have a global account array for the whole transaction consisting of staticAccountKeys and any potentially resolved LUTs. Then, when we want to say that our instruction references accounts ABC and DEF we provide the index of these two accounts in our global array. This is what accountKeyIndexes refers to, your instruction takes the accounts at index 1 and 2. (That way if two instructions want account ABC we don't need 32 bytes of space for each, instead we need 1x 32 bytes for the account and 2x 1 byte for the index).

PS: To be able to fully parse the instruction you'll need to reconstruct this entire global array which includes resolving LUTs. This question explains how this is done.

1

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.