# anchor-patterns-and-pitfalls

> Safe Anchor constraint recipes, space and PDA design, zero-copy, and the traps that survive Anchor.

anchor-patterns-and-pitfalls is a paid AI agent skill on Agensi by BanditXBT. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $3.15 (one-time purchase)
- Creator: [BanditXBT](https://www.agensi.io/creators/banditxbt)
- Version: 1.0
- Last updated: 2026-11-21
- Security: scan passed (2026-11-21); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/anchor-patterns-and-pitfalls
- Tags: apis-backend, web3-crypto, code-quality-review

## About this skill

Anchor removes boilerplate, not responsibility: its safety exists only where you declare constraints.

- `Account<'info, T>`: owner == program, discriminator matches `T`, data deserialized. Use for your own state.
- `Signer<'info>`: `is_signer` verified. Authority accounts must use this (or `#[account(signer)]`).
- `Program<'info, P>` / `Interface<'info, I>`: validates callee program ID (use for CPI targets; `Interface` for Token-2022 compatibility).
- `InterfaceAccount<'info, Mint|TokenAccount>`: works for SPL Token and Token-2022.
- `SystemAccount`, `Sysvar<'info, T>`: validated type/address.
- `UncheckedAccount`/`AccountInfo`: **no checks**. Require a `/// CHECK:` comment that states the manual validation actually performed, and perform it.

`space = 8 (discriminator) + field sizes`; `Pubkey` 32, `u64` 8, `bool` 1, `Option<T>` 1+size, `String` 4+max_len, `Vec<T>` 4+max_len·size, enums = 1 + max variant. Use `#[derive(InitSpace)]` with `#[max_len(n)]`. Wrong space causes runtime deserialization failures or silent truncation of intended fields. Plan versioning: reserve padding (`_reserved: [u8; N]`) or a `version` field for upgrades.

Accounts above ~10 KB or hot-path structs: use `#[account(zero_copy)]` with `AccountLoader` (no deserialization copy; stack is 4 KB per frame, heap 32 KB). Zero-copy structs need `#[repr(C)]`/`Pod` alignment and explicit padding; test layout with `size_of`. Use `realloc` constraint (`realloc::payer`, `realloc::zero`) for growth; max +10 KiB per instruction.

## Requires

- Rust
- Anchor

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the anchor-patterns-and-pitfalls skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What does anchor-patterns-and-pitfalls do?

Safe Anchor constraint recipes, space and PDA design, zero-copy, and the traps that survive Anchor.

### Which AI agents support anchor-patterns-and-pitfalls?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use anchor-patterns-and-pitfalls?

Connect your AI agent to Agensi through MCP, then ask it to use anchor-patterns-and-pitfalls on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
