1

I have the following struct in my anchor program.

pub struct CustomStruct {
    pub user: Pubkey,
    pub number: u64
}

How would I go about checking for null values / default values for user and number?

I'm assuming for u64, I can check u64 == u64(0) or something similar.

Not sure how to check for null Pubkey.

2
  • Hmm... what's your larger goal here? Are you trying to determine if an account has already been initialized? If so, you could add a boolean property to your struct and use that as a flag. But more generally, you should only initialize accounts once (in the instruction where you tag them with init). All other instructions can then assume the account is already initialized. Commented Nov 25, 2022 at 20:07
  • got it- yeah boolean could work but I'd prefer to not add additional fields if not needed. the larger goal is that I want the anchor program to have an if else statement if the account is or is not set.
    – AceGravity
    Commented Nov 28, 2022 at 15:39

1 Answer 1

0

If you initialize an account with that structure and don't specify the pubkey, the default value will be "111111111111111111111111111111111", which is the system program.

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.