Using PDAs for Data Storage
Program-Derived Addresses (PDAs)
Chapter 3: Using PDAs for Data Storage
PDAs are perfect for storing program state, such as counters or user data.
Key Points:
PDAs function like regular accounts but are program-controlled.
Ideal for global or user-specific state.
Example: Incrementing a counter.
Code Example:
#[account]
pub struct Counter {
pub count: u64,
}
pub fn increment(ctx: Context<Increment>) -> Result<()> {
ctx.accounts.counter.count += 1;
Ok(())
}
Interactivity: Simulate incrementing the counter and see the updated value.
Last updated