2

Hello!

(I'm new to Solana blockchain)

I have a problem with finding schema for base64 encoded data field. I use websocket connection and subscribe to base vault address using accountSubscribe method. This vault account is owned by Raydium Authority V4.

Response looks like:

{
  "jsonrpc": "2.0",
  "method": "accountNotification",
  "params": {
    "result": {
      "context": {
        "slot": 298423747
      },
      "value": {
        "data": [
          "ykGKaepGFLQHCirRxFiYQFSme+FyzCJg4Yt5R8zsSARBV7BYDzHF/ORKYlgtvPnXjudZQ6CEo5OzUDaNIomTCGAvdCo8RQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
          "base64"
        ],
        "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "rentEpoch": 18446744073709551615,
        "lamports": 2039280,
        "executable": false,
        "space": 165
      }
    },
    "subscription": 16127
  }
}

I have tried to find any schema in github Raydium repositories, but nothing found, however found raydiym-idl, but I don't know how to use it in order to deserialize the bytes that I get after decoding data. I need an example how to do it in Rust.

Thanks

2 Answers 2

2

Based on what you described, I think this repository can help you: https://github.com/thlorenz/chainparser

1
  • thanks, i will try it now
    – Plz help
    Commented Nov 1 at 14:26
0

Hello,

Recently, I worked on decoding Raydium transactions in Rust, and I believe this approach can help with your case. Below is a sample code snippet demonstrating how to decode Base64-encoded instruction data, which is common in Solana transactions:

use bincode;
use base64;
use std::error::Error;

fn decode_base64_instruction_data(base64_data: &str) -> Result<(u64, u64), Box<dyn Error>> {
    // Decode the Base64 string into a byte array
    let decoded_data = base64::decode(base64_data)?;
    
    // Assuming the relevant data starts at index 8
    let (value1, value2): (u64, u64) = bincode::deserialize(&decoded_data[8..])?;
    Ok((value1, value2))
}

fn main() -> Result<(), Box<dyn Error>> {
    // Example Base64-encoded string (16 bytes data + 8 bytes metadata)
    let base64_data = "AAAAAAAAAAoAAAAAAAAUAAAAAAAAAA=="; // Represents [0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0]
    
    // Decode and extract values
    let (amount, max_sol_cost) = decode_base64_instruction_data(base64_data)?;
    println!("Amount: {}, Max SOL Cost: {}", amount, max_sol_cost);

    Ok(())
}

Explanation:

Base64 Decoding: The instruction data is typically Base64 encoded in Solana transactions. This code decodes the string into a byte array.

Deserialization: The byte array is then deserialized into u64 values using bincode. Here, it starts reading data after the first 8 bytes of metadata.

Example Output: The Base64 example decodes to two u64 values: Amount: 10, Max SOL Cost: 20.

You can adjust the deserialization logic based on the specific structure of the transaction data you're working with. This approach should make it easier to handle and process Solana transaction instructions in your Rust application.

Hope this helps!

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.