Build Solana programs with Anchor framework or native Rust. Use when developing Solana smart contracts, implementing token operations, testing programs, deploying to networks, or working with Solana development. Covers both high-level Anchor framework (recommended) and low-level native Rust for advanced use cases.
/plugin marketplace add tenequm/claude-plugins/plugin install solana@tenequm-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/accounts.mdreferences/anchor.mdreferences/builtin-programs.mdreferences/compute-optimization.mdreferences/cpi.mdreferences/deployment.mdreferences/durable-nonces.mdreferences/error-handling.mdreferences/native-rust.mdreferences/pda.mdreferences/production-deployment.mdreferences/resources.mdreferences/security.mdreferences/serialization.mdreferences/surfpool.mdreferences/sysvars.mdreferences/testing-frameworks.mdreferences/testing-overview.mdreferences/testing-practices.mdreferences/tokens-2022.mdBuild Solana programs using Anchor framework or native Rust. Both approaches share the same core concepts (accounts, PDAs, CPIs, tokens) but differ in syntax and abstraction level.
Anchor provides macros and tooling that reduce boilerplate and increase developer productivity:
use anchor_lang::prelude::*;
declare_id!("YourProgramID");
#[program]
pub mod my_program {
use super::*;
pub fn initialize(ctx: Context<Initialize>, data: u64) -> Result<()> {
ctx.accounts.account.data = data;
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = user, space = 8 + 8)]
pub account: Account<'info, MyAccount>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct MyAccount {
pub data: u64,
}
When to use Anchor:
Installation:
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest
anchor --version
Create project:
anchor init my_project
cd my_project
anchor build
anchor test
→ See references/anchor.md for complete Anchor guide
Native Rust provides maximum control, optimization potential, and deeper understanding of Solana's runtime:
use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
pubkey::Pubkey,
msg,
};
entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
msg!("Processing instruction");
// Manual account parsing and validation
// Manual instruction routing
Ok(())
}
When to use Native Rust:
Setup:
cargo new my_program --lib
cd my_program
# Configure Cargo.toml (see native-rust.md)
cargo build-sbf
→ See references/native-rust.md for complete native Rust guide
Essential knowledge for all Solana developers, regardless of framework:
Create a new program:
anchor init my_project → anchor.md#getting-startedcargo new my_program --lib → native-rust.md#setupInitialize a PDA account:
#[account(init, seeds = [...], bump)] → pda.md#anchorinvoke_signed with System Program → pda.md#nativeTransfer SPL tokens:
anchor_spl::token::transfer → tokens-operations.md#transferring-tokensTest your program:
anchor test for integration tests → testing-frameworks.md#anchor-specific-testingLocal development with mainnet forking:
surfpool start for mainnet-forked local network → surfpool.mdTest with mainnet state (Jupiter, Raydium CPIs):
Profile compute units in detail:
surfnet_profileTransaction cheatcode → surfpool.md#transaction-profilingDeploy to devnet:
anchor deploy → deployment.md#anchorsolana program deploy → deployment.md#nativeDeploy to production (verified builds):
solana-verify build + solana program deploy → production-deployment.mdOptimize compute units:
Handle 40+ accounts:
Offline transaction signing:
| Your Need | Recommended Approach | Reason |
|---|---|---|
| Standard DeFi/NFT program | Anchor | Faster development, proven patterns |
| TypeScript client needed | Anchor | Auto-generates IDL and client types |
| Learning Solana fundamentals | Native Rust first | Understand the platform deeply |
| Compute optimization critical | Native Rust | Direct control, minimal overhead |
| Advanced tx features (ALTs, nonces) | Either (slight edge to Native) | Framework-agnostic features |
| Fast prototyping | Anchor | Less boilerplate, faster iteration |
| Maximum control over every detail | Native Rust | No abstraction layer |
| Team familiar with frameworks | Anchor | Lower learning curve |
| Program size matters | Native Rust | Smaller compiled programs |
Note: You can also start with Anchor for rapid development, then optimize critical paths with native Rust patterns if needed.
| Aspect | Anchor | Native Rust |
|---|---|---|
| Setup complexity | Simple (anchor init) | Manual (Cargo.toml, entrypoint) |
| Boilerplate | Minimal (macros handle it) | Significant (manual everything) |
| Account validation | Declarative (#[account(...)]) | Manual (explicit checks) |
| Serialization | Automatic (Borsh via macros) | Manual (Borsh or custom) |
| Type safety | High (compile-time checks) | High (but more verbose) |
| IDL generation | Automatic | Manual or tools |
| Client library | TypeScript + Rust auto-gen | Manual client code |
| Testing | anchor test, Mollusk | Mollusk, cargo test |
| Deployment | anchor deploy | solana program deploy |
| Compute overhead | Small (~1-3% typical) | None (direct) |
| Program size | Slightly larger | Smaller |
| Learning curve | Gentler (abstractions help) | Steeper (need SVM knowledge) |
| Debugging | Good (clear macro errors) | More complex (lower level) |
| Community | Large (most use Anchor) | Growing (optimization focus) |
anchor init my_project#[derive(Accounts)] with constraints#[program] module#[account] macro for account structurestests/, run anchor testanchor deploy to configured networkcargo new my_program --lib, configure Cargo.tomlprocess_instruction functioncargo testcargo build-sbfsolana program deploy target/deploy/program.so✅ Always validate accounts: Check ownership, signers, mutability
✅ Use checked arithmetic: .checked_add(), .checked_sub(), etc.
✅ Test extensively: Unit tests, integration tests, edge cases
✅ Handle errors gracefully: Return descriptive errors
✅ Document your code: Explain account requirements and constraints
✅ Version your programs: Plan for upgrades and migrations
✅ Use PDAs for program-owned accounts: Don't pass private keys
✅ Minimize compute units: Profile and optimize hot paths
✅ Add security.txt: Make it easy for researchers to contact you
✅ Use InitSpace derive: Auto-calculate account space
✅ Prefer has_one constraints: Clearer than custom constraints
✅ Use Program<'info, T>: Validate program accounts in CPIs
✅ Emit events: Use emit! for important state changes
✅ Group related constraints: Keep account validation readable
✅ Use next_account_info: Safe account iteration
✅ Cache PDA bumps: Store bump in account, use create_program_address
✅ Zero-copy when possible: 50%+ CU savings for large structs
✅ Minimize logging: Especially avoid pubkey formatting (expensive)
✅ Build verifiable: Use solana-verify build for production
Both frameworks require security vigilance:
⚠️ Common vulnerabilities:
→ For defensive programming patterns and secure coding practices, see security.md
That guide provides:
→ For comprehensive security audits, use the solana-security skill
That skill provides:
Start with Anchor, optimize later:
Start with Native, add Anchor features:
Use both in a workspace:
[workspace]
members = [
"programs/core", # Native Rust
"programs/wrapper", # Anchor facade
]
New to Solana?
Coming from another blockchain?
Want to optimize?
Building production apps?
solana-security skillThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.