Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
A minimal Anchor program defining a counter with increment and reset functionality, demonstrating the use of Anchor macros and client interaction.
#[program]
mod counter {
use super::*;
#[state]
pub struct Counter {
pub value: u64,
}
impl Counter {
pub fn new(ctx: Context<New>) -> Result<Self> {
Ok(Counter { value: 0 })
}
pub fn increment(&mut self, ctx: Context<Increment>) -> Result<()> {
self.value += 1;
Ok(())
}
pub fn reset(&mut self, ctx: Context<Reset>) -> Result<()> {
self.value = 0;
Ok(())
}
}
}Anchor is a Rust-based framework for Solana smart contract (program) development, testing, and deployment. It simplifies building Solana dApps by providing a high-level abstraction over Solana programs and client interactions.
Origin & Creator
Anchor was created by Project Serum team members in 2020 to simplify Solana program development, reduce boilerplate, and improve developer productivity.
Industrial Note
Anchor is widely used in DeFi, NFT, and other Solana ecosystem projects, as it standardizes Solana program structure and automates common patterns like account validation and serialization.