Skip to main content
In this quickstart guide, you’ll build, test, and deploy a simple counter program using the Anchor framework. This hands-on tutorial will teach you the fundamentals of Anchor program development.

What you’ll build

You’ll create a counter program that:
  • Creates a counter account to store data
  • Increments the counter value
  • Validates account ownership and authority
  • Demonstrates Anchor’s account constraints

Prerequisites

Before you begin, ensure you have installed:
  • Rust
  • Solana CLI
  • Anchor CLI
  • Node.js and Yarn
See the Installation guide if you need to install these dependencies. Verify Anchor is installed:
Expected output:

Build the counter program

Understanding the code

Let’s break down the key components:

Program structure

Space calculation

When initializing accounts, you must specify the space:
  • 8 bytes: Account discriminator (automatically added by Anchor)
  • 32 bytes: Pubkey for authority
  • 8 bytes: u64 for count
Total: 48 bytes

Account constraints

Anchor provides powerful constraints for security:
  • init - Create and initialize an account
  • mut - Account data can be modified
  • has_one - Validate account relationships
  • constraint - Custom validation logic
  • signer - Account must sign the transaction
See the Account Constraints reference for a complete list.

Next steps

Congratulations! You’ve built and deployed your first Anchor program. Here’s what to explore next:

Program structure

Learn about Anchor macros and program architecture

Account constraints

Explore all available account validation constraints

TypeScript client

Build frontend applications with the Anchor TS client

Examples

Browse more example programs and tutorials