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?
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?
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.