Anchor Cli Development Tutorials, Guides & Insights
Unlock 1+ expert-curated anchor cli tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your anchor cli skills on DeveloperBreeze.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Tutorial
javascript bash +2
Building a Simple Solana Smart Contract with Anchor
Replace the contents with the following code to create a counter program:
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWxTWG9AAM9QK2ZrhQWk5raUB7Uq");
#[program]
pub mod counter {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
let counter = &mut ctx.accounts.counter;
counter.count = 0;
Ok(())
}
pub fn increment(ctx: Context<Increment>) -> ProgramResult {
let counter = &mut ctx.accounts.counter;
counter.count += 1;
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = user, space = 8 + 8)]
pub counter: Account<'info, Counter>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct Increment<'info> {
#[account(mut)]
pub counter: Account<'info, Counter>,
}
#[account]
pub struct Counter {
pub count: u64,
}Aug 09, 2024
Read More