I am trying to derive a pda using a u32 number. It seems that the seeds can only take u8 numbers. Is there a way to change this and use a u32 number as input for the seed?

enter image description here

edit: I am using Anchor.

  • does user_id.uid.to_be_bytes() work ?
    – vicyyn
    Commented Aug 10, 2022 at 8:42

1 Answer 1


Convert u32 to u8 array with to_be_bytes()

  • Would you perhaps know what format to send the u32 number from the frontend? Can't get this in the same format when I use the to_be_bytes() in the Anchor program. Deriving the PDA in Anchor: #[account(init, payer = user, space = 8 + 8 + 32 + 1 + 32 + 1 + 10, seeds = [b"user_profile".as_ref(), &user_id.uid.to_be_bytes().as_ref() ], bump)] The seeds in the front-end: anchor.utils.bytes.utf8.encode('user_profile'), new anchor.BN(user_id_pda.uid).toBuffer(), Where the uid is a u32 number (user_id.uid and user_id_pda.uid).
    – Nelis.sol
    Commented Aug 10, 2022 at 11:10
  • e.g. new anchor.BN(18) will send u32 to anchor program from the frontend
    – vicyyn
    Commented Aug 10, 2022 at 12:17

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.