Développement de programmes Solana

VérifiéSûr

Guide les assistants IA dans l'écriture, le test et le déploiement de programmes Solana avec Rust natif ou le framework Anchor. Il facilite la validation des comptes, l'utilisation des PDA, les CPI et les tests avec LiteSVM, bankrun ou Mollusk.

Spar Skills Guide Bot
DeveloppementIntermédiaire
8002/06/2026
Claude CodeCursorWindsurfCopilotCodex
#solana#anchor#rust#blockchain#smart-contracts

Recommandé pour

Notre avis

Ce guide aide les assistants IA à rédiger, tester et déployer des programmes Solana (contrats intelligents) en utilisant Rust natif ou l'framework Anchor.

Points forts

  • Couverture complète du cycle de vie d'un programme Solana, du scaffolding au déploiement.
  • Accent sur les bonnes pratiques (validation des comptes, PDA, gestion des erreurs, optimisation des unités de calcul).
  • Inclusion de modèles pour Anchor et Rust natif, ainsi que des stratégies de test avec LiteSVM et bankrun.
  • Prise en charge des patterns avancés comme les CPI avec declare_program!.

Limites

  • Ne remplace pas une compréhension approfondie du modèle de compte de Solana.
  • Les fichiers de référence (anchor-programs.md, etc.) doivent être présents dans la base de connaissances pour une utilisation optimale.
  • Ne couvre pas la conception de tokens SPL ni les interactions avec des programmes tiers spécifiques.
Quand l'utiliser

Idéal pour développer un nouveau programme Solana, implémenter des instructions complexes, ou déboguer des erreurs on-chain.

Quand l'éviter

Évitez si vous travaillez sur un projet Solana existant avec une architecture non standard nécessitant une connaissance contextuelle hors du guide.

Analyse de sécurité

Sûr
Score qualité80/100

The skill provides instructional guidance for writing Solana programs, using code examples and patterns. It does not instruct the AI to execute any commands that could cause harm, nor does it contain obfuscated or malicious content. All operations are purely code-authoring advice.

Aucun point d'attention détecté

Exemples

Basic Anchor program for token staking
Write an Anchor program for a token staking system where users can stake SPL tokens and earn rewards. Include instructions to stake, unstake, and claim rewards. Use PDA for the staking account.
Debugging on-chain error
I'm getting a 'Program failed to complete' error when calling my Solana program. Can you help me debug it? Here's the instruction code...
Deploying to devnet
Guide me through deploying my Anchor program to Solana devnet, including building the BPF and using the Solana CLI to deploy.

Solana Program Development

Description

Guides AI assistants in writing, testing, and deploying Solana programs (smart contracts) using both native Rust and the Anchor framework.

When to Use

  • Writing a new Solana program (on-chain code)
  • Implementing program instructions, accounts, state
  • Working with PDAs, CPIs, or system instructions
  • Testing programs with LiteSVM, bankrun, or Mollusk
  • Deploying or upgrading programs
  • Debugging on-chain program errors

Instructions

For New Programs

  1. Ask if the user prefers Anchor (recommended) or native Rust
  2. Determine the program's purpose and required accounts
  3. Scaffold the project structure
  4. Implement instruction logic with proper validation
  5. Write tests
  6. Guide deployment

Key Principles

  • Always validate all accounts — check ownership, signers, writable
  • Use PDAs for program-derived state (avoid storing keypairs)
  • Handle errors explicitly with custom error enums
  • Minimize compute units — Solana has per-instruction limits (200k default, 1.4M max per tx)
  • Consider rent exemption for all account creation
  • Use declare_program! (Anchor 0.30+) for CPI to avoid dependency hell

Reference Files

Common Patterns

Anchor Program Skeleton

use anchor_lang::prelude::*;

declare_id!("YOUR_PROGRAM_ID");

#[program]
pub mod my_program {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>, data: u64) -> Result<()> {
        ctx.accounts.my_account.data = data;
        ctx.accounts.my_account.authority = ctx.accounts.authority.key();
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(
        init,
        payer = authority,
        space = 8 + MyAccount::INIT_SPACE,
        seeds = [b"my_account", authority.key().as_ref()],
        bump,
    )]
    pub my_account: Account<'info, MyAccount>,
    #[account(mut)]
    pub authority: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
#[derive(InitSpace)]
pub struct MyAccount {
    pub authority: Pubkey,
    pub data: u64,
}

PDA Derivation

// On-chain
let (pda, bump) = Pubkey::find_program_address(
    &[b"seed", user.key().as_ref()],
    &program_id,
);

// In Anchor constraints
#[account(
    seeds = [b"seed", authority.key().as_ref()],
    bump,
)]
pub my_pda: Account<'info, MyData>,

CPI Pattern (Anchor 0.30+ with declare_program!)

// In idls/other_program.json (place the IDL there)
declare_program!(other_program);

// Use in your program:
use other_program::cpi;
cpi::some_instruction(ctx, args)?;
Skills similaires