0

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": [
                "3cSSMT43FQCgBAT4KCxJsUULFy9P258AUdnvwK76dvkB",
                "E8M7hoiYsJZnwhML1Q7ot6S73mcW6qfoEyUuFtGvmepU",
                "6GvCe4zhWwQqToG7jPrVaoBXRNhn7aT99gG4QZas8kYf",
                "GWnZKcgBq55K2WaBEFmiuv8Gcq9siySYpu4A24uPAcCH",
                "8P7hQpgn4v2HPSyDkX9VJVVExQ5S1sf3YQEMHcg8HoLv",
                "4F86x89wFGmRg8RtYA1zwkR7xdooim5g9eS6ZF6TYhcF",
                "FeY3rti4By34aE61qCNL9MnWGBPT2o8LM2gzYEMtemzp",
                "2bmzR5tAUWUXCFJvvoWPw5nacVdES7Qw1TtgkEAdXv37",
                "9iq7ewwfRAXUYZ6ZgStSa6SDhQ5h3uudM6et22FX6FDT",
                "GzgjLJQuu3TNeJi9B242huJVTDoJwueTHuAbSQjrEBm6",
                "AXMjwxHaWj9rYQ12PhTVnqVnT3hCtcT53ejGVaLMNT9p",
                "ER7bFuygbrTiw3s1gmQrLmZJSzGA38kbf22NfJH7kbtK",
                "Ck3T2nRCFK4CRKhMsGa14oNPcsdJrf8a6EKpeY7BDenU",
                "F9Jcfi17FSzbNrpZ1pvcGrXUi57PvWz36LDMj9yQnDhn",
                "So11111111111111111111111111111111111111112",
                "34geSnvYBUfqthfSRjMW2iByt2egMrqJ49wpixYE3pem",
                "11111111111111111111111111111111",
                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                "4PGwUH7o4xoePV6xpAXCLQp2LBDnLjpyJTXEch1t81Tj",
                "ComputeBudget111111111111111111111111111111",
                "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
                "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
            ],
            "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": [
"264LHUKwinwdKRN5i3VDHfzjz1ffxv1yD6wE3JEnDsSoFTCgz6bWwVfmmBW1b3HKE5ptKdAr43qokY9hxRWZ1YcY",
"3p7eAciagCWcDX5hzwr6gz5waNQUvPuZCCe4YPVhLvHvsGM6F8Tnmwhj5xwjx7NEAo8gVzzT8WSxDGpuKoeGiK3J"
        ]
     },
       "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

0

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.

13
  • 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.