When developing Solana on-chain programs with Anchor, after running anchor build, structs that are decorated with #[account] attribute will be in the generated IDL file. I'm wondering if I can turn this off? i.e., I don't want some structs to be in the IDL.

(Edit) The reason why I want to turn off IDL generation for some types is because some generated IDLs are somewhat incorrect in my code implementation. I've posted the issue here in another question on Solana Stack Exchange.

2 Answers 2


This is technically possible, but it's a little goofy.

If you implement the AnchorSerialize and AnchorDeserialize traits by hand, you can omit an implementation for IdlBuild, which will skip including that type in the IDL.

More info at https://github.com/coral-xyz/anchor/blob/d9a9f193947ec869e60eab58453f1791fff06576/lang/syn/src/idl/build/defined.rs#L18

I would question the premise of doing this though. Your program's IDL allows any client to interact with your program by creating instructions and interpreting account data.

When your program decorates a struct with #[account], it's including that type in the interface, and thus required for people interacting with your program. By removing a type from the IDL but still requiring a type, your program becomes harder to use.

  • Oh I don't know there's such a trait (i.e., IdlBuild) that is used to build IDL. Thanks a lot. p.s., I've also updated the reason why I want to turn off IDL generation in the question.
    – Yan
    Commented Mar 12 at 2:13

Other than obfuscation I can't think of any reason you would want to do this. If your goal is just to hide the structure of the account for some reason, you can turn your data into bytes before serializing it and store it on-chain as:

pub struct SomeStruct {
    some_bytes: [u8; 1024],

You can use bytemuck to convert to/from bytes into/from your actual struct.

Even if you hide the structure in the IDL, anyone can see the bytes on-chain, so this is the best you can do.

  • Thanks! I've also updated the reason why I want to turn off IDL generation in the question
    – Yan
    Commented Mar 12 at 2:14

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.