I am trying to pass parameters of types: float, int, bool, pubkey to Solana anchor program instructions from web3js library
#[account]
pub struct Parent {
pub field1: String,
pub field2: u8,
pub field3: f64,
pub field4: Pubkey,
}
I am using the following approach to serialize a string parameter
// serializing a string parameter
const data = 'sample data';
const string_u8vec = new TextEncoder().encode(data)
const string_u8vec_length = Buffer.from(new Uint8Array(new BN(string_u8vec.length).toArray("le", 4)));
const instructionBuffer = Buffer.concat([
ixBuffer, // namespace+method_name
string_u8vec_length, // the length of the string
string_u8vec // the string itself
])
What is the correct way to serialize all other data types mentioned above? And is there a common method to serialize all data types or we should handle each differently?
Please help. Thanks