in-solana by Supanode

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

  1. Uninitialized account. The account exists but has not been initialized by the program. Its data is all zeros or has no discriminator.
  2. Wrong account type. You passed a mint account where a token account is expected, or vice versa.
  3. Data too small. The account was allocated with fewer bytes than the program’s data struct requires.
  4. Account already closed. The account was previously closed and its data was zeroed out, but the address is being reused.

How to fix

  1. Initialize the account first. Call the program’s initialize instruction before using the account in other instructions.
  2. Check account size. Use getAccountInfo to verify data.length matches the expected size.
  3. 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: