"A pirate must always account for their actions, for the seas will not forget."
Important! Account and Accounts Struct are different things!!! In Solana, an account refers to a single instance of data storage on the blockchain, identified by a unique address. For example:
#[account]
#[derive(Default)]
pub struct MyAccount {
data: u64
}
On the other hand, accounts refers to a collection of accounts that a program needs to interact with during a particular transaction on the Solana blockchain. A program can interact with multiple accounts at once, and the accounts keyword is used to define a struct that specifies the accounts needed for a particular operation.
#[derive(Accounts)] attribute is used to specify a struct that defines a collection of accounts that a program needs to interact with. For example we use accounts for the account above MyAccount
#[derive(Accounts)]
pub struct SetData<'info> {
#[account(mut)]
pub my_account: Account<'info, MyAccount>
}
We will cover accounts again later. Also you will learn about PDA's. But for now, we don't hold any state in our program. We are just logging message to chain. Got it? For now, we just adding this Initialize struct for using context below our code. Please copy and paste it to your code :)
#[derive(Accounts)]
pub struct Initialize<> {}
As you can see we use context accounts struct as a parameter in order to use accounts. In further chapters we will see detailed usage of it.