SolWipe logoSolWipeCheck Wallet
You might have SOL you don't know about. Check for free.
Getting Started Solana Development

Getting Started with Anchor on Solana: A Beginner's Guide

SW
SolWipe Team
··4 min read

Anchor on Solana is a powerful framework designed to simplify the development of decentralized applications (dApps) on the Solana blockchain. If you're a developer looking to dive into Solana development, understanding Anchor is crucial. This beginner's guide will walk you through the fundamental steps of getting started with Anchor on Solana, from setting up your environment to deploying your first application.

What is Anchor and Why Use It?

Anchor is a framework designed to build Solana programs quickly and safely. It provides a set of tools and conventions that streamline the development process, making it easier to write secure and efficient smart contracts. Here are some key reasons why you should consider using Anchor:

Benefits of Using Anchor

  • Ease of Use: Anchor abstracts many complexities associated with Solana development, allowing you to focus on building features rather than handling low-level details.
  • Built-in Safety Features: It incorporates Rust programming best practices, reducing the likelihood of bugs and vulnerabilities in your code.
  • Strong Community Support: Anchor has a growing community of developers and extensive documentation, making it easier for beginners to find resources and assistance.
  • Familiar Syntax: If you have experience with Rust, you’ll find Anchor’s syntax and structure intuitive and accessible.

By leveraging these benefits, you can expedite your development process and create robust applications that take full advantage of the Solana blockchain.

Setting Up Your Development Environment

Before you can start building with Anchor, you need to set up your development environment. This process involves installing several tools and dependencies.

Required Tools

  1. Rust: Anchor is built with Rust, so you’ll need to install it. You can download Rust through rustup.

  2. Solana CLI: Install the Solana command-line interface (CLI) to interact with the Solana blockchain. Follow the installation instructions on the Solana documentation.

  3. Anchor CLI: Finally, install the Anchor CLI, which provides commands to create, build, and deploy Anchor programs. You can install it using Cargo:

    cargo install anchor-cli --locked
    

Initial Setup

Once you have the required tools installed, you’ll need to configure your Solana CLI. Run the following command to set your Solana cluster:

solana config set --url https://api.devnet.solana.com

This command sets your environment to use the Devnet blockchain, which is ideal for testing and development.

Verifying the Installation

To ensure everything is set up correctly, you can run the following commands:

  • Check Rust installation:

    rustc --version
    
  • Check Solana CLI installation:

    solana --version
    
  • Check Anchor CLI installation:

    anchor --version
    

If all commands return the expected version numbers, you’re ready to move on to building your first Anchor program.

Building Your First Anchor Program

Now that your environment is set up, let’s create a simple Anchor program. This program will be a basic counter that increments a value stored on the blockchain.

Step 1: Create a New Project

Use the Anchor CLI to create a new project:

anchor init counter

This command creates a new directory called counter with a default project structure.

Step 2: Define Your Program

Navigate to the counter directory and open lib.rs found under programs/counter/src/. Here, you’ll define the program's logic. Replace the existing code with the following:

use anchor_lang::prelude::*;

declare_id!("YourProgramID");

#[program]
mod counter {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
        let counter_account = &mut ctx.accounts.counter_account;
        counter_account.count = 0;
        Ok(())
    }

    pub fn increment(ctx: Context<Increment>) -> ProgramResult {
        let counter_account = &mut ctx.accounts.counter_account;
        counter_account.count += 1;
        Ok(())
    }
}

#[account]
pub struct CounterAccount {
    pub count: u64,
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(init, payer = user, space = 8 + 8)]
    pub counter_account: Account<'info, CounterAccount>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct Increment<'info> {
    #[account(mut)]
    pub counter_account: Account<'info, CounterAccount>,
}

Step 3: Update Your Cargo.toml

Make sure to include the required dependencies in your Cargo.toml file. Under the [dependencies] section, add:

anchor-lang = "0.18.0" # Check for the latest version

Step 4: Build the Program

To compile your program, navigate to the root of your project directory and run:

anchor build

If the build is successful, you should see output indicating that your program has been compiled without errors.

Deploying and Testing Your Application

With your program built, it’s time to deploy it to the Solana blockchain and test its functionality.

Step 1: Deploy the Program

To deploy your program, run the following command:

anchor deploy

This command will upload your program to the Solana Devnet. Once deployed, you’ll receive a program ID that you can use to interact with your program.

Step 2: Interact with Your Program

You can interact with your deployed program using the Solana CLI or by writing tests in Rust. For testing purposes, let’s create a simple script.

  1. Navigate to the tests folder in your project.
  2. Create a new file named counter.js and add the following code:
const anchor = require('@project-serum/anchor');

async function main() {
    const provider = anchor.Provider.env();
    anchor.setProvider(provider);

    const program = anchor.workspace.Counter;

    const counterAccount = anchor.web3.Keypair.generate();
    await program.rpc.initialize({
        accounts: {
            counterAccount: counterAccount.publicKey,
            user: provider.wallet.publicKey,
            systemProgram: anchor.web3.SystemProgram.programId,
        },
        signers: [counterAccount],
    });

    console.log("Counter initialized");

    await program.rpc.increment({
        accounts: {
            counterAccount: counterAccount.publicKey,
        },
    });

    const account = await program.account.counterAccount.fetch(counterAccount.publicKey);
    console.log("Counter Value: ", account.count.toString());
}

main().then(() => console.log('Done')).catch(err => console.error(err));

Step 3: Run Your Test

Make sure you have Node.js installed, and then run the following command to execute your script:

node counter.js

If everything is set up correctly, you should see the initialized counter value and the incremented value printed in the console.

Step 4: Clean Up

If you want to remove any empty token accounts created during your development, consider using tools like SolWipe to help you close those accounts efficiently.

Conclusion

Getting started with Anchor on Solana opens up a world of possibilities for building decentralized applications. By following this guide, you’ve learned the basics of setting up your development environment, creating your first program, and deploying it to the Devnet. As you continue to explore Solana development, consider diving deeper into topics like what are token accounts or understanding rent exemption explained.

Now that you have a foundation in Anchor, you can start building more complex applications and contributing to the ever-growing Solana ecosystem. For additional guidance and tools, be sure to check out the SolWipe guide for managing your Solana accounts effectively. Happy coding!

Recover your hidden SOL now

Connect your wallet, scan for free, and claim your locked SOL in under 30 seconds.

Find My Hidden SOL →

More from SolWipe

View all articles →
Advanced Wallet Features Multisig

10 Best Tools for Managing Squads on Solana

Squad management in the Solana ecosystem is essential for teams looking to streamline their operations and enhance collaboration. With the rise of decentralized finance and blockchain applications, managing squads effectively has become crucial. Utilizing the

Feb 20, 2026
Decentralized Storage Computing Filecoin

10 Best Use Cases for the Akash Network in 2026

The Akash Network is revolutionizing the way we think about cloud computing by providing a decentralized platform for hosting applications and services. By connecting users in need of cloud resources with providers who have excess computing power, Akash Networ

Feb 20, 2026
Privacy Cryptocurrency Mixers Zeroknowledge

10 Crypto Mixers You Should Know About in 2026

When it comes to maintaining crypto anonymity, using top crypto mixers is a crucial step for individuals looking to enhance their privacy in transactions. As the landscape of cryptocurrency continues to evolve, ensuring your digital footprint remains discreet

Feb 20, 2026
Solana Blockchain Explorers Analytics

10 Must-Know Solana Data Tools for Investors in 2023

Investing in the Solana blockchain can be both exciting and daunting. With its rapid growth and innovative technology, the need for effective Solana data tools for investors is more crucial than ever. These tools help you make informed decisions, analyze marke

Feb 20, 2026
Blockchain Technology Fundamentals Blockchains

10 Ways Consensus Algorithms Impact Blockchain Performance

Consensus algorithms are a foundational element of blockchain technology, determining how transactions are validated and how nodes in the network come to an agreement. Understanding how consensus algorithms impact blockchain performance is crucial for anyone i

Feb 20, 2026
Sol Investing Fundamentals Buying

2023 Solana Investment Trends: What You Need to Know

The Solana blockchain has gained significant traction in the crypto space, and understanding the Solana investment trends for 2023 can help you make informed decisions. As the ecosystem evolves, it’s essential to stay updated on market dynamics, emerging use c

Feb 20, 2026