1

I have a u64 which is an amount of lamports. I need to send it to another program with a CPI. So i'm trying to encode it in the data, but can't figure out how to do it.

Here is what i tried:

let mut instruction_discriminator: Vec<u8> = vec![38, 29, ...];
let mut instruction_data: Vec<u8> = price_in_lamports.to_be_bytes().to_vec();
instruction_discriminator.append(&mut instruction_data);

but then in the programm called thru the CPI, when i log the amount received, it's totally different (wayyyy bigger), so i guess i'm doing something wrong here. Anyone can help ?

1 Answer 1

2

I don't know your programs but potentially you just need to use little-endian instead of big-endian.

Try with to_le_bytes and see if that works. Most programs (including the system program) encode their instraction parameters as le.

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.