Account types in Anchor
Suggest an editEvery field in an Accounts struct has a type. It tells Anchor what kind of account this slot expects, what checks to run before your handler executes, and what your handler can do with the field once it gets there. There are five types you'll use day to day, and each one verifies something different.
The type says what the program accepts in a slot
A program does not choose the accounts it runs on. The client that builds the transaction lists every account the instruction touches (see instructions and transactions), and the runtime passes the program those accounts and nothing else. Whoever sends the transaction decides which account sits in each slot, so for every slot the program has to state what it accepts.
The field's type is the first place you state it. When you write pub vault: Account<'info, Vault> inside an Accounts struct, you are telling Anchor to perform a specific set of checks on whichever account appears in that slot of the transaction. If any of those checks fail, the transaction is rejected before your handler runs. If all of them pass, the field becomes available inside your handler as a fully typed value, ready to read or write. Each of the five types packages a different set of checks, because what counts as valid depends on the role the account plays in the instruction. Pick the most specific type that fits.
The five types, one at a time
Signer<'info>. The account whose keypair authorized the transaction. Anchor verifies one thing: a signature from this account's public key was attached to the incoming transaction. It does not check the account's owner, its data, or its balance. So the sender cannot put someone else's wallet in this slot without that wallet's signature. Use it for the wallet that's calling your instruction. Anything labeled "authority," "owner," or "user" in your design almost certainly wants this type.
Account<'info, T>. It says three things at once: the account is owned by the program that defines T (your program, for a type you declare with #[account]), its data starts with the 8-byte discriminator that identifies a T, and the rest of its data deserializes cleanly into the T struct. So the sender cannot pass an account that belongs to another program, or an account of your program that stores a different type. By the time your handler runs, ctx.accounts.vault is a reference to a typed Vault you can read and write like any Rust struct. Use this for every piece of state your program owns.
SystemAccount<'info>. A regular wallet on the chain, owned by the System Program. Use it when an instruction needs to reference a wallet that isn't signing the transaction. A common case is a recipient of a SOL transfer: the recipient doesn't sign, but you want to make sure the slot really holds a plain wallet rather than some random account you'd accidentally clobber.
Program<'info, T>. The account is the deployed program of type T. Anchor verifies the account's address matches the program's known address and that its executable flag is true. So the sender cannot pass a different program in place of the one you mean to call. Use it when your instruction calls into another program: Program<'info, System> to invoke the System Program and create an account, Program<'info, Token> to call the Token Program and move tokens.
UncheckedAccount<'info>. Anchor performs no checks on it. Whatever account the client sends in this slot is what your handler receives, as a raw AccountInfo you have to validate yourself. Use it only when none of the other types fit, and always pair it with a /// CHECK: doc comment explaining why it's safe and what you're doing to validate it. anchor build refuses to build without that comment. Common legitimate uses include accounts you constrain with a fixed address (#[account(address = ...)]), or accounts whose validation is performed by a CPI you're about to make. Older Anchor code uses AccountInfo<'info> directly, the raw type that the runtime hands to a program: an account's public key, owner, lamports, data, and flags. Anchor treats an AccountInfo field the same way, with no checks and the same /// CHECK: requirement. UncheckedAccount is a thin wrapper around it whose name says that nothing is checked, so prefer UncheckedAccount.
If the manual validation is missing, the slot accepts anything. Wormhole lost about 320 million dollars in 2022 this way. Its program needed the list of the transaction's instructions, which a program reads from the instructions sysvar (a system account with a fixed address that the runtime fills with data). The program read the list from whatever account the caller passed in that slot and never compared its address with the real sysvar address. The root of trust lecture of the Solana Pro course covers the incident.
A withdrawal struct that uses all five
A withdrawal from a vault can use every type at once. The vault holds program state, the owner signs to authorize the withdrawal, the recipient is a wallet that doesn't need to sign, and the transfer happens by calling into the Token Program. The struct also takes a price oracle account. No Anchor type fits it, but it is constrained to a specific address, so it appears as an UncheckedAccount<'info> with a /// CHECK: comment explaining the address pin.
A type says what kind of account the slot holds, but not which one. Account<'info, Vault> accepts any Vault account your program owns, and Signer<'info> accepts any wallet that signed the transaction. Nothing in the types of this struct ties authority to the authority recorded in vault, so with types alone a stranger could sign as authority and pass someone else's vault. Tying accounts to each other is the job of account constraints, the next lesson.
Pick the type at the first yes
When you add a field to a new instruction, ask the four questions below in order and take the type at the first yes. If every answer is no, you reach for UncheckedAccount, and the comment you write next is your justification.