Account Model Best Practices
Design account layouts that scale, stay safe, and minimize rent and compute costs on Agave 4.1.1.
Search across all documentation pages
Design account layouts that scale, stay safe, and minimize rent and compute costs on Agave 4.1.1.
#[account] structInitSpace + max_len for variable fields. Never guess String/Vec sizes in Anchor 0.32.1.version byte when schema will evolve. Append-only field changes prevent deserialization breakage.mut account has owner + authority checks. Account<T>, has_one, seeds, or explicit constraint.UncheckedAccount without constraints. Treat as guilty until proven valid.Signer + has_one together, not either alone.getMinimumBalanceForRentExemption in clients. Do not hardcode rent lamports.realloc sparingly with migration plan. Prefer new account types for breaking changes.seeds exactly.getProgramAccounts by discriminator. Reduces RPC payload and client decode work.Missing owner/authority validation on writable accounts - leads to drain vulnerabilities.
Accounts larger than a few KB read/written frequently. Measure CU before migrating.
One per logical object (position, order, vault). Avoid dozens per action to limit rent UX cost.
Yes for frictionless onboarding when rent exceeds user tolerance - budget treasury accordingly.
Map each instruction to every mut account; list runtime checks applied.
Only with strong seeds and authority checks - otherwise attackers initialize on victim's behalf.
#[max_len(N)] on field; InitSpace includes 4 + N in total.
One owner program only. Share data via CPI or read-only passing, not dual ownership.
New PDA + copy instruction + deprecate old type. Never reorder existing Borsh fields.
Yes - seeds = [b"config"] singleton is standard for protocol parameters.
Use for massive low-mutability datasets (cNFTs). Not for hot DeFi state.
Fast local tests for init/close/realloc without full validator overhead.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026