in the package @solana/web3.js there is such type AccountMeta
/**
* Account metadata used to define instructions
*/
type AccountMeta = {
/** An account's public key */
pubkey: PublicKey;
/** True if an instruction requires a transaction signature matching `pubkey` */
isSigner: boolean;
/** True if the `pubkey` can be loaded as a read-write account. */
isWritable: boolean;
};
I use this type to decode the data. I get the data from transactions. After poking around in this data, I can't find any information about isSigner and isWritable. Where to get them?
raw data looks like this
{
blockTime: 1705557623,
indexWithinBlock: 248,
meta: {
err: null,
fee: 6400,
innerInstructions: [],
loadedAddresses: { readonly: [], writable: [] },
logMessages:[],
postBalances: [],
postTokenBalances: [],
preBalances:[],
preTokenBalances: [],
rewards: []
},
slot: 242508962,
transaction: {
message: {
accountKeys: [Array],
addressTableLookups: null,
header: [Object],
instructions: [Array],
recentBlockhash: ''
},
signatures:''
]
},
version: 'legacy'
}
I'm taking the data from all the keys.
tx.transaction.message.accountKeys => [
'9iGipTrLnL8qWWUPoBBxiktcdfDPUJRKAv2xeCG1K7UU',
'5jjxRiSnBPTE8WDCBnGRw4n9zXcpgXYowyGVN2JVuQ3E',
'73p6jUhJ1iRB2Prc5qEfserpFprFs5QhwqYfNzjXeATQ',
'ComputeBudget111111111111111111111111111111',
'11111111111111111111111111111111',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
'So11111111111111111111111111111111111111112',
'675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8'
]
taking instructions
tx.transaction.message.instructions => { accounts: [ 1, 6, 0, 19 ], data: '2', programIdIndex: 5 }
the numbers in accounts accounts: [ 1, 6, 0, 19 ]
are indices from the AccountsKeys array?
How to work with them? Where do they refer to?
because I get Error TokenInvalidInstructionKeysError when decoding.
decode with decodeInstruction from @solana/spl-token
For the decodeInstruction
function from @solana/spl-token you need to provide an array of keys. which will have values matching the AccountMeta
type. But I did not find information about isSigner and isWritable in the transaction data. Where to get them?
So, two questions. Where to get information about isSigner and isWritable? from the raw data I showed you above. I want to provide this information to the decodeInstruction function
second question, what do these numbers in the accounts field indicate?
I don't think they are indexes, because index number 19, from accounts: [1, 6, 0, 19]
would be undefined, since accountKeys
doesn't have that many keys.
if they are indices, it means that there are missing keys in the accountKeys
data array. Is this even possible?
update.
Thanks for your comments, it helped me. i want to make sure i understand the situation correctly. Since my headers are different. Could you please give me an example based on this data.
accountKeys: [
'DG5Ba67Ys5U5JcrMjcE3urmorYErguhuViLg7CuZy4Nq',
'EUUpDKRbWWFtA8SrKgiEMBvvsG3YST7bWHo4nJVimV2Q',
'E6TsJB737Mm85VaJtQJSoMkZS619UU6qLLUx3qDSevZx',
'6vLZ6Kz46rRsC9EsRwYP1C2Cqwfq4jA9SMjVzK1MmoQ5',
'9DCxsMizn3H1hprZ7xWe6LDzeUeZBksYFpBWBtSf1PQX',
'6Hqq4Zxdqj6HzLS11y5vEnCd2qxT1gQtG4NjCJ3D8CGu',
'EP6kxz5emawLyZ1MrwZsejcZ3YjvLwxJheriUwAQyJJV',
'Eo1HHS36tkXAmWtr9a6vWAqL9WnZGiFzmCwd6r1Ayaqv',
'HX9RH6AXiwjZbrzp2aaBw7vVTqJL6qP4XAgxH9bTP9rK',
'A5aZrtA7MQZ1W31Dew2rEw2gBboVPR7XZeQ24QaGpzzW',
'5BHWbF5cbAPb6CgrqNoFHme1a7QDqcV1NGqbpyTe7ywz',
'3GAjr3LTaP4VAYv1eiSTFoGYkrmGwmaEebdbya8K38Qq',
'4NFdKk5up2xAmQKRUwrcFPKp77tw8HXRxKPh52HgRat3',
'B7fmLgen6Rniq8EBgPrT4HSzPrfe4JTMSJxALuRNB31B',
'K1LRSA1DSoKBtC5DkcvnermRQ62YxogWSCZZPWQrdG5',
'ComputeBudget111111111111111111111111111111',
'11111111111111111111111111111111',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
'So11111111111111111111111111111111111111112',
'675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8',
'5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1',
'2ws3teGMs2Z9PhVLZjPnfPxU7zFdT7jTSojXRVe1Ctjs'
]
headers: {
numReadonlySignedAccounts: 0,
numReadonlyUnsignedAccounts: 7,
numRequiredSignatures: 1
}
insturction: { accounts: [ 1, 18, 0, 22 ], data: '2', programIdIndex: 17 }