How can I convert the data to the same form as it is done on the solana explorer for better readability?
1 Answer
Generally speaking, on-chain transactions are just a bunch of serialized bytes, so to parse it you need to have some more context on what programs it's interacting with. For starters, if it's interacting with a limited amount of solana standard programs, web3.js
can parse these out of the box using getParsedTransactions.
This won't work for most programs, though. If you know which program you want to parse, you can try to find it's IDL and use that to parse transactions with anchor. Details on how to do this can be found here.
Finally, if you want to parse a lot of different types of transactions, it basically comes down to collecting and indexing IDLs and matching them with whichever program your transaction is interacting with. Doing this by hand is very tedious, but fortunately there's a couple libraries that do this for you, for example: