Skip to main content
edited title
Link

How to encode array data (Uint8Array) for instruction?

Source Link

How to encode array data (Uint8Array)?

I am trying to call a function using a non-anchor program from solana. The function takes a [u8:32] argument as "seeds" and a u32 argument as "number_of_schedules". I have looked all over the docs online and no information on this is available, or they only show how to encode basic data like instruction index. Here is my layout:


  const dataLayout = BufferLayout.struct([
    BufferLayout.u8('instruction'),
    BufferLayout.u32('seeds'), // I don't think this is right; should be [u8; 32] but can't find that
    BufferLayout.u32('number_of_schedules')
  ]);
  const data = Buffer.alloc(dataLayout.span);
  dataLayout.encode(
    {
      instruction: 0, // 0 for create instruction,
      seeds: seeds,
      number_of_schedules: new BN(3),
    },
    data,
  );

please help me