Open-sourcing the Solana Transaction Parser

Building a powerful tool for projects and developers

Open-sourcing the Solana Transaction Parser

At deBridge, we’ve been building for Solana for almost a year now and developed a set of internal development tools that we plan to gradually open-source to all Solana builders. Today, we’re thrilled to open-source the first Transaction Parser for Solana, giving developers a tool to easily read and decode transactions into a human-friendly format. You can find the Parser on GitHub here.

Solana transactions are defined through ABI, a program interface that determines the transaction structure, including the sequence of arguments and the way a transaction is encoded. Before being sent to the blockchain, transactions are serialized and packed as binary instructions data, which is difficult to read.

In the past, to restore the arguments of any instruction out of the instruction data, developers needed to manually write the code or carefully decode it.

Instruction data parsing is needed to debug transactions, read on-chain data, create analytics, cross-chain interactions, and much more. We have developed a framework that enables the decoding of arbitrary Solana instructions based on Interface Definition Language (IDL) or using a custom parsing scheme.

With our newly open-sourced Solana Transaction Parser, every developer has now the ability to inspect the contents of a serialized message for debugging and development in the Solana ecosystem. Let’s dive into the details and explain how to get started.


Intro to Anchor

The Anchor project implements all the low-level components you need to parse transactions (instructions processor, arguments serialization, etc) but all the programs written with Anchor consume more computation resources than a program written without this framework. Furthermore, Anchor makes interaction with on-chain programs easy since low-level instructions preparations are performed by Anchor typescript client using IDL. IDL is a file generated during contract compilation that contains a list of instructions with needed args (including their types) and accounts, similar to EVM ABI.

Parsing instructions using IDL

Typescript SDK allows us to easily serialize/deserialize instructions using IDL, but we need to perform some common steps such as: initialize instruction coder, try to decode instruction, check if decoding succeeds, prepare list of decoded accounts and set correct types. These are clearly tasks that should be automated.

This is exactly what we’ve built for you at deBridge! Now, you can easily initialize the parser using IDL and program ID. Let’s dive into how it works step-by-step:

Printing parsed will emit something like this:

CPI

What if we want to use a proxy contract that will take some arguments, modify them, and call another contract with provided args using Cross Program Invocation (CPI)?

We can extract args passed to the proxy contract from the transaction dump but we need transaction processing results to get CPI data. Let’s set the parse CPI flag to true and check what’s going on during a Jupiter swap.

9W959DqEETiGZocYWCQPaJ6sBmUzgfxXfqGeTEdp3aQP is an Orca (Whirlpool) address, so this instruction looks like “Orca Swap”. Let's try to reverse-engineer this instruction and write a custom parser. The data structure looks like [instruction id (u8), value 1 (u64 little endian), value 2 (u64 little endian)], and accounts are similar to the Jupiter variant. The custom parser looks like this:

Let’s add a custom parser and try to parse the same transaction.

The Parse result looks much better.

Now it looks like an explorer variant but is available from the code:

Logs

Solana allows you to emit logs during execution. You may want to process these logs after transaction finalization for monitoring purposes. Let’s assume that we need to extract all logs emitted by Cykura’s SwapCallback. We just extract the transaction from the chain and then call a function called parseLogs which emits logs with its context.

Filtering logs by programId and log messages is simple:

And it emits everything we need during the process!

Comprehensive and human-friendly tooling can be a real growth catalyst for any blockchain ecosystem, giving developers a way to navigate ever-changing architectures. By building and open-sourcing the Solana Transaction Parser, we’re thrilled to be able to start contributing to Solana’s tooling stack, and hopefully, give developers and projects a useful new tool in their arsenal!

Website | deSwap | Docs | Discord | GitHub | Twitter | Telegram

Success
Thank you for subscribing!
Error
Subscribe link expired