Disclaimer: I asked this on SO and also in Discord, but was directed here, so here I am...
I'm doing a simple transaction with a single transfer instruction for 0,1 SOL from one account to another. Then in my backend service I want to get the transaction and verify the data it carries - specifically that a transfer has been made for 0,1 SOL.
I use getTransaction with the tx signature and get a response like this:
{ message: Message { header: { numReadonlySignedAccounts: 0, numReadonlyUnsignedAccounts: 1, numRequiredSignatures: 1 }, accountKeys: [ [PublicKey], [PublicKey], [PublicKey] ], recentBlockhash: '9S44wiNxXZSdP5VTG6nvaumUJBiUW1DGUXmhVfuhwTMh', instructions: [ [Object] ], indexToProgramIds: Map(1) { 2 => [PublicKey] } }, signatures: [ '8ykRq1XtgrtymXVkVhsWjaDrid5FkKzRPJrarzJX9a6EArbEUYMrst6vVC6TydDRG4sagSciK6pP5Lw9ZDnt3RD' ] } So, I dig into message.instructions and find the following object:
{ accounts: [ 0, 1 ], data: '3Bxs411Dtc7pkFQj', programIdIndex: 2 } Ok, so data is the base58-encoded string '3Bxs411Dtc7pkFQj'. I decode that from base58 (using bs58), but that only gives me a Uint8Array, which I am not really sure how to convert into a JS object.
I can see in the tx in Solscan that the data information is decoded into hex:
And I can also get this same info in my script:
---> Instructions: { accounts: [ 0, 1 ], data: '3Bxs411Dtc7pkFQj', programIdIndex: 2 } ---> Instructions Data: base58: 3Bxs411Dtc7pkFQj hex: 0200000000e1f50500000000 But not sure what to do next. How do I get the actual info inside the data?
So, I guess the question is: How to decode the instruction data into a JS object?
