0

I would like to decode a sell instruction from a transaction, to obtain instruction detail. Idem as make Solscan with a transaction after we sell an NFT on Opensea or Magiceden. For example the code to get an instruction from a transaction is:

const result = await connection.getParsedTransaction(signature)
result.transaction.message.instructions[NUMBER].parsed

but sometimes I got an "undefined" response, and sometimes I got the response. For example I got the response from Transfer Instruction. But not all instruction can be decoded. So I want to know a correct way to do this. Here is an example of transaction with 6 instruction and the first one is the Sell instruction and I can't get a correct response from the code above. https://solscan.io/tx/3mdZshAycXoGKRHENrWpVYfAhtjEMQqXcLRXcbE1Y3E9hstNTWie9i1MCYneTbrtddK7xg2P8aEHFoS8hAeXu1WL

2 Answers 2

2

Solana enforces no serialization or data structure on account/instruction data, so programs are free to implement both however they wish. This makes it impossible to generically parse the data fields

As such, the parsing is done by the RPC node, which only knows about programs/instructions for which parsers have been explicitly added. Most likely the program/instruction you wish to inspect does not have a parser added. You can likely parse the data field yourself, but will likely need documentation or a helper library provided by the given protocol. Not all protocols provide such information though, so you would need to reverse engineer the data format in that case

0
  • Regarding the undefined resonse that you sometimes get, this is likely caused by the commitment you are requesting the transaction with. Change it to a lower commitment, so you can get the data quicker and more consistently, would be an idea.
  • To get the data, you may need to deserialize the instruction data of the inner instructions using a library or by hand.

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.