I work with decoding data. I use the @solana/spl-token package for that.

sometimes I get the TokenInvalidInstructionKeysError error

I have this code ts. as keys I provide an array of keys that I have selected by index from the message.accountKeys array

import { decodeInstruction } from '@solana/spl-token'

    const decodeDataTokenProgram = decodeInstruction({
      keys: instruction.keys, // keys corresponding to the index from message.accountKeys
      programId: instruction.programId,
      data: instruction.data

I read that document, but I'm not quite sure what they mean https://solana.com/ru/docs/rpc/json-structures

according to the documentation: accounts: <array[number]> - List of ordered indices into the message.accountKeys array indicating which accounts to pass to the program.

the indices are there. But what about the last index? For example, there is index 22, but we will get undefined by this index. Does it mean that if we get the last index, we should always take -1 and we will get index 21. It's a bit misleading, to be honest.

I posted the raw data for you to look at. https://pastebin.com/a32KZ55E

please give me an example of how I can use addressTableLookups to decode an instruction

Using this data as an example, please show me how to work with an array of accounts

    "transaction": {
        "message": {
            "accountKeys": [
            "addressTableLookups": [
                    "accountKey": "FUigYUS3EPJB682u6mCgvox7JMfHn6KxqhYdnLmqm2pe",
                    "readonlyIndexes": [4, 21,20],
                    "writableIndexes": []

         "header": {
            "numReadonlySignedAccounts": 0,
            "numReadonlyUnsignedAccounts": 8,
            "numRequiredSignatures": 2
        "instructions": [
              "accounts":[ 1, 14, 0, 22 ],
              "data": "2",
              "programIdIndex": 17
        "signatures": [
       "version": 0

In this instruction, the last element of the accounts array is 22. If we rely on this number, the index from accountKeys will return undefined.

please tell me how to work with this instruction? in the context of decodeInstuction function from @solana/spl-token

update. i added an array of addressTableLookups.Question how to work with this array? the documentation gives examples of how to create it, not how to work with it. thank you

1 Answer 1


This transaction is using an address from a lookup table.

You will need to set the request parameters encoding to json and the maxSupportedTransactionVersion to 0 in the getTransaction request .

And the full list of account meta will be available.

  • thank you. Yes I am getting version 0 data. there is an addressTableLookups array. I was reading the documentation and I didn't understand how to get data from this array. The documentation only talks about creating such tables
    – slntrx
    Commented Jan 22 at 3:03
  • There’s additional data in the response and the field name is transaction.
    – wei1769
    Commented Jan 22 at 3:05
  • I'm sorry, I didn't understand you. I added the data I get, could you show me more clearly how to connect this instruction and the addressTableLookups array? thanks
    – slntrx
    Commented Jan 22 at 3:09
  • What’s your parameters for the getTransaction request?
    – wei1769
    Commented Jan 22 at 3:12
  • 1
    you mean add the values from the loadedAddresses array to the end of the accountKeys array?
    – slntrx
    Commented Jan 22 at 3:48

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.