AccountNotInitialized
The Anchor program expected an account that is already initialized (has a valid discriminator and data), but received an uninitialized or zeroed-out account.
Common causes
- Account not created yet. The
initinstruction for this account was never called, so the account has no discriminator. - Wrong account passed. You passed a different account that does not have the expected Anchor discriminator.
- Account was closed. A previous
closeinstruction zeroed out the account’s data and reclaimed the lamports. - Discriminator mismatch. The account exists and has data, but the 8-byte discriminator at the start does not match the expected account type.
How to fix
- Initialize first. Call the instruction that creates the account (typically an
initializeorcreateinstruction) before using it in other instructions. - Check the discriminator. Use getAccountInfo and check the first 8 bytes of the account data. They should match the SHA256 hash of
account:<AccountName>. - Verify the account address. If using a PDA, ensure the seeds and bump produce the expected address.
Anchor account lifecycle
New account → init (allocate + set discriminator) → use → close (zero data + reclaim SOL)
An account is “initialized” in Anchor when:
- It has enough data allocated
- The first 8 bytes contain the correct discriminator
- The remaining data can be deserialized into the expected struct
FAQ
What is the Anchor discriminator?
An 8-byte identifier stored at the beginning of every Anchor account. It is the first 8 bytes of SHA256("account:<AccountStructName>"). The framework checks it automatically on every instruction to ensure the right account type is passed.
What is custom program error: 0xBC4?
Hex 0xBC4 is decimal 3012, which maps to AccountNotInitialized in Anchor’s account error range (3000–3999).
Can I reinitialize a closed account?
Yes, but you must call the init instruction again. The init constraint checks that the discriminator is zeroed, so it will only work on accounts that were properly closed or never initialized.
Error text variants
-
AccountNotInitialized -
AccountNotInitialized (3012) -
custom program error: 0xBC4 -
The program expected this account to be already initialized
Updated: