I'm trying to fetch an account from a public key:
await program.account.myAccountType.fetch(somePubkey);
But then Anchor throws an error saying:
Invalid account discriminator
What is an account discriminator?
An account discriminator is few bytes that Anchor puts at the front of an account, like a header. It lets anchor know what type of account it should deserialize the data as.
This error happens if you try to to fetch something as myAccountType
, but it's actually a pubkey for some other account, like a Token Account, or another account within your program.
Here's some things you could try:
somePubkey
and putting it into the explorerprogram.account.myAccountType
and not program.account.someOtherAccountType
.