> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/solana-foundation/anchor/llms.txt
> Use this file to discover all available pages before exploring further.

# Account constraints

> Complete reference for Anchor account constraints

Account constraints provide automatic validation and security checks.

## Initialization constraints

### init

Initialize a new account.

```rust theme={null}
#[account(init, payer = user, space = 8 + 8)]
pub data: Account<'info, Data>
```

**Required with:**

* `payer` - Who pays for the account
* `space` - Account size in bytes

### init\_if\_needed

Initialize only if the account doesn't exist.

```rust theme={null}
#[account(init_if_needed, payer = user, space = 8 + 8)]
pub data: Account<'info, Data>
```

## Mutability constraints

### mut

Mark account as mutable.

```rust theme={null}
#[account(mut)]
pub data: Account<'info, Data>
```

## Validation constraints

### has\_one

Validate an account field matches another account.

```rust theme={null}
#[account(has_one = authority)]
pub data: Account<'info, Data>
```

Checks: `data.authority == authority.key()`

### constraint

Custom validation expression.

```rust theme={null}
#[account(constraint = data.value < 100)]
pub data: Account<'info, Data>
```

## PDA constraints

### seeds

Validate PDA derivation.

```rust theme={null}
#[account(
    seeds = [b"data", user.key().as_ref()],
    bump
)]
pub data: Account<'info, Data>
```

### bump

Specify bump seed for PDA.

```rust theme={null}
#[account(seeds = [b"data"], bump = data.bump)]
pub data: Account<'info, Data>
```

## Closing constraints

### close

Close account and return lamports.

```rust theme={null}
#[account(mut, close = authority)]
pub data: Account<'info, Data>
```

## Reallocation constraints

### realloc

Change account size.

```rust theme={null}
#[account(
    mut,
    realloc = 8 + new_size,
    realloc::payer = user,
    realloc::zero = true
)]
pub data: Account<'info, Data>
```

## Token constraints

For SPL token accounts:

```rust theme={null}
#[account(
    init,
    payer = user,
    token::mint = mint,
    token::authority = authority
)]
pub token_account: Account<'info, TokenAccount>
```

See [SPL Integrations](/advanced/spl-integrations) for token constraint details.

## Complete reference

See the [source code](https://github.com/solana-foundation/anchor/tree/master/lang/attribute/account/src) for all constraints.
