4

This question is the converse of What is the use for `program_id` in program's entrypoint.

What is the point of declare_id!(), because the program_id is passed as an argument to the the entrypoint?

1 Answer 1

3

declare_id!() is a macro to define a static public key. We often need to use static public key. (For example, for defining system programs like stake_instructions). In those cases, we can not define static public key directly from the string. (Try to define static pubkey from string using Pubkey::from_str. It will throw an error). We can build static public key from u8 array using Pubkey::new_from_array but that is not readable. Thus declare_id is used for defining static public keys for those cases.

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.