1

I wanna have magicEden's program IDL. https://solscan.io/account/M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K

I can see many transactions here, and what I want to achieve is to get listing price info from this transaction logs.

example: ) https://solscan.io/tx/5TUrNVydwNnzJvk8rUx4Msn5bQuTF4DrN97YKFqgMqbfTxhWjvuVb6rqy596BcwV4PvRU8FdP229vDHDb4qjr52o

There I can see Program log: {"price":9050000000,"buyer_expiry":0}, which means price lamports are 9050000000. Also There's are instruction data 66063d1201daebeafffc800a6c1b0200000001000000000000000000000000000000

I wanna parse this data into readable data. Is there any way to parse it? I think getting IDL would make this work easier.

1 Answer 1

2

You can extract the price by analyzing instruction data. In your example, you know from the logs that listing price is 9050000000. Using any decimal to hex converter, we can see that in hex this number is represented as 800a6C1b02 (make sure you are converting to little-endian).

Next, we can easily spot this number in instruction data (highlighted with brackets).

66063d1201daebeafffc[800a6c1b02]00000001000000000000000000000000000000

Is starts at 10-byte offset. Solana uses 64-bit unsigned integers for prices, so we will need bytes [11-18].

800a6c1b02000000

Here is sample code in Rust:

use core::convert::TryInto;

let data = "66063d1201daebeafffc800a6c1b0200000001000000000000000000000000000000";
let byte_vec = hex::decode(&data[20..36]).unwrap(); // each byte takes 2 chars, so bytes 10-18 will be multiplies by 2
let price = u64::from_le_bytes(byte_vec.try_into().unwrap());
println!("Listing price: {}", price);

// output: "Listing price: 9050000000"

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.