InvalidAccountData for instruction
The program tried to deserialize an account’s data but the content does not match the expected format, size, or state.
Common causes
- Uninitialized account. The account exists but has not been initialized by the program. Its data is all zeros or has no discriminator.
- Wrong account type. You passed a mint account where a token account is expected, or vice versa.
- Data too small. The account was allocated with fewer bytes than the program’s data struct requires.
- Account already closed. The account was previously closed and its data was zeroed out, but the address is being reused.
How to fix
- Initialize the account first. Call the program’s
initializeinstruction before using the account in other instructions. - Check account size. Use getAccountInfo to verify
data.lengthmatches the expected size. - Verify account type. Ensure you are passing the right kind of account. For SPL Token: mint accounts and token accounts are not interchangeable.
How to prevent
- Always check that accounts are initialized before passing them to instructions that read their data.
- Use getAccountInfo to inspect account data and owner before building transactions.
- For Anchor programs, the framework validates account discriminators automatically — this error usually means you passed a wrong account.
FAQ
What is an account discriminator? Anchor programs store an 8-byte hash at the start of each account’s data to identify the account type. If the discriminator does not match, deserialization fails with InvalidAccountData.
Can I resize an account?
Yes. Use realloc in your program to change the account’s data size. The account must have enough SOL to remain rent-exempt at the new size.
Error text variants
-
InvalidAccountData for instruction -
InvalidAccountData -
invalid account data for instruction
Updated: