Welcome to Project 4. We are going to build a Journal App. This app will allow users to Create, Read, Update, and Delete journal entries entirely on the Solana blockchain.
In a traditional database like PostgreSQL, updating or deleting rows is trivial. On a blockchain, data is stored in Accounts, and you must pay Rent (in Lamports) for the space your data occupies.
If you update a string on-chain and it becomes longer than the original string, you must reallocate space for the account and transfer more rent to it. If you delete an account, you want to get that rent money back!
We will start by defining the JournalEntryState struct.
#[account]
#[derive(InitSpace)]
pub struct JournalEntryState {
pub owner: Pubkey,
#[max_len(50)]
pub title: String,
#[max_len(1000)]
pub message: String,
}
We use #[max_len()] again because Anchor needs to know the absolute maximum size this account could ever be to calculate INIT_SPACE.
Open-source source: https://github.com/solana-developers/developer-bootcamp-2024/tree/main/project-4-crud-app
Lesson Exam