1

I'm trying to write a simple go program to parse Solana transactions (swaps mostly) to establish a framework to collect ohlc data, based on sol transactions.

( I have done this for several other block chains,but having a real hard time doing this for Solana, due to lack of familiarity)

Could some point me in the right direction of some go with some examples how to accomplish this?

Right now I'm using RPC calls to get the slot, associated block and transactions. But I'm a bit stuck.with decoding these.

As an example, I would love to parse this transaction:

https://solscan.io/tx/4MxyeXUQfEAKH7z8X9fNomNAF1CcQ87LH47zqj3EbwaLMwiM5ABA8WKgtADN3Pu2VS354Rsbe5LTEe43QawXJE1d

and extract this information:

Swap 0.048 image WSOL for 0.048204732 image WSOL on Jupiter Aggregator v6

Thank you!

1 Answer 1

1

Ok looks like I good a rough solution working. It's not final, but enough to get other people started

Assuming you are using anchor-go

  1. download your IDL file, in this case we assume jupiter.idl
  2. install anchor-go using: go install github.com/gagliardetto/anchor-go
  3. generate the bindings: anchor-go --remove-account-suffix --src jupiter.json
  4. sadly right now you need to fix some minor compile errors. Mostly it complains about missing structs, which can be solved, by removing 'Swap' in front of the generated types.go files
  5. utilize the following code fragment as a starting point
    utx, err := client.GetTransaction(context.TODO(), sig, &rpc.GetTransactionOpts{
        MaxSupportedTransactionVersion: &txVersion,
    })

    tx, err := utx.Transaction.GetTransaction()

    meta, err := tx.AccountMetaList()

    for _, instruction := range tx.Message.Instructions {
        parsedInstruction, err2 := jupiter.DecodeInstruction(meta, instruction.Data)

        print("instructions %v, %s ", parsedInstruction, err2)
    }

This will now provide you with the swapped data, where for a given transaction we are able to decode the content. If it fails, an error is generated and we move on. This will only give you the partial instructions. I update this, when I find the complete answer in a couple of days.

If you debug the transaction object, it could look something like this:

enter image description here

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.