upd: https://docs.solana.com/developing/programming-model/transactions#instruction-data here, my task is to decode this data using js
I tried to solve the issue with this post How to get Solana instruction data from transaction object but never got around to it. that's why I'm here.
I am listening to events token program at address TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. i am getting data within which there are transactions, there are instructions in the messages. an example of an instruction is shown below. The question is how to decode them
how to decode data received from token program instructions ?
{
accounts: [ 0, 1 ],
data: '3ipZWiVHsLw9kjb4qJon6pADjViJNbKrcEVtxfZZWdkbq8KMxZegM1ecZbkz6VGvYVdH8BjqSy69GfVjCkGto52xTgtJhLygZeRAuVdThpvb5mbfFC2GjAUCYD8MAWKn1Ri6FH5JknmM2qBncCykyDsDqbjeNhNpEoYR4WNw2',
programIdIndex: 4
}
or
{ accounts: [], data: 'JzwPro', programIdIndex: 3 }
or
{
accounts: [
0, 8, 11, 6, 16, 9, 4,
10, 2, 3, 1, 5, 7, 17,
15, 14, 12, 21, 19, 20
],
data: '5k2cQw4xSusHX5',
programIdIndex: 18
}
I realized that I need to have a scheme for decoding. Since I get the data when I monitor the token program at the address TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
. Then I assume that there is already a working decoder for this program. But I tried using decodeTransfer
from the @solana/web3.js
package. As a result I get TypeError: Cannot read properties of undefined (reading 'equals'). I have not found a solution for this error. So, how to decode the data correctly?
I also found this json file, for spl tokens. But I didn't understand how to use it to decode data https://github.com/acheroncrypto/native-to-anchor/blob/master/client/packages/spl-token/idl.json maybe you know how to use this json to decode the instructions?
please give me an example for decoding data with js.
and raw data looks like this
{
blockTime: number,
indexWithinBlock: number,
meta: {
err: null,
fee: 15000,
innerInstructions: [],
loadedAddresses: { readonly: [], writable: [] },
logMessages: [],
postBalances: [],
postTokenBalances: [],
preBalances: [],
preTokenBalances: [],
rewards: []
},
slot: 242069085,
transaction: {
message: {
accountKeys: [Array],
addressTableLookups: null,
header: [Object],
instructions: [Array],
recentBlockhash: string
},
signatures: [string]
},
version: 'legacy'
}
from this data, I'm pulling instructions