In this post, I'll go through what causes the cryptic error message "Smart contract panicked: panicked at 'Cannot deserialize the contract state.: Custom { kind: InvalidData, error: "Not all bytes read" }"
.
When you deploy smart contracts and store information, the state is serialized and stored on disk. A problem arises when you deploy another smart contract to your account and you've changed important information. The NEAR Runtime will try to read your serialized state from disk and load it using whatever smart contract code is deployed to your account. If it can't figure out how to do this, it will output the error the Not all bytes read
error message.
For an example of when this could happen, see the upgrade a contract section of the NFT zero to hero tutorial found in our DevDocs.
To read about the best practices and how to avoid such scenarios, refer to this detailed article.