Anchor for Solana Setup: Configuration, Tests, Deployment

We design and develop full-cycle blockchain solutions: from smart contract architecture to launching DeFi protocols, NFT marketplaces and crypto exchanges. Security audits, tokenomics, integration with existing infrastructure.
Showing 1 of 1All 1305 services
Anchor for Solana Setup: Configuration, Tests, Deployment
Medium
from 4 hours to 2 days
Frequently Asked Questions

Blockchain Development Services

Blockchain Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1358
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1251
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    957
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1188
  • image_logo-advance_0.webp
    B2B Advance company logo design
    646
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    929

You spent a day installing Solana CLI and Anchor, only to hit error[E0308]: mismatched types in generated code. Sound familiar? Version conflicts are the top headache when setting up a Solana environment. Anchor 0.30.x demands Solana CLI 1.18.x, while Anchor 0.29.x worked with 1.17.x. Simply installing the latest of both often yields a broken project and hours of debugging. Our turnkey setup eliminates this pain: we've configured environments 30+ times and know every pitfall. You save up to 40 hours of debugging and up to $2000 in lost development time — contact us for a certified consultation.

Why version conflicts trip up newcomers

Version incompatibility isn't limited to Solana CLI. Rust, Anchor, and even Node.js versions can suddenly break builds. A typical scenario: anchor build crashes with error[E0308]: mismatched types in generated code. The root cause? Anchor 0.30.x uses Solana 1.18.x, but your system has 1.17.x. Compatibility table guaranteed by our certified experience:

Anchor Solana CLI Rust
0.30.1 1.18.17 1.75+
0.29.0 1.17.34 1.72+
0.28.0 1.16.x 1.70+

How AVM solves version switching

AVM (Anchor Version Manager) lets you switch Anchor versions without manual hassle — a guaranteed fix for 90% of conflicts:

# Install AVM and Anchor
git clone https://github.com/coral-xyz/anchor.git
cargo install --git https://github.com/coral-xyz/anchor avm --force
avm install 0.30.1 && avm use 0.30.1
# Install compatible Solana CLI
sh -c "$(curl -sSfL https://release.anza.xyz/v1.18.17/install)"

After installation, verify solana --version and anchor --version. If they don't match, you know the culprit. Our certified process ensures compatibility within 15 minutes.

Detailed setup steps (certified by 30+ projects)

  1. Install Rust via rustup (1.75+ for Anchor 0.30).
  2. Install Solana CLI v1.18.17 using the Anza release script.
  3. Install AVM and Anchor 0.30.1 using the avm install command.
  4. Create project with anchor init — automatically generates IDL (anchor idl) and TypeScript client.
  5. Configure Anchor.toml for localnet, devnet, or mainnet.
  6. Run anchor test — verifies solana test validator integration and anchor deploy flow.
  7. For mainnet, use solana program deploy with squash protocol and store program keypair in cold storage.

If an error occurs, it's usually a version mismatch. Use our compatibility table or contact us for guaranteed resolution.

Anchor vs. Native Solana: a concrete comparison (Anchor is 5x faster)

Anchor reduces test program deployment time by 3x compared to manual compilation. Compare:

Aspect Anchor Native Solana
IDL Automatic Manual
TypeScript types Generated Manual
Account deserialization Automatic Manual borsh
PDA (anchor pda) Macros Manual findProgramAddress
Versioning AVM solana cli
Development speed High (5x) Medium

Anchor delivers 5x faster code writing through declarative macros and code generation. For production, choose Anchor — fewer errors, easier maintenance, and guaranteed solana pda derivation.

Why Anchor excels in complex projects with solana program

Account constraints are a key Anchor feature that automatically verifies access rights and PDA derivation. Example:

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

seeds + bump ensure automatic PDA derivation and verification, eliminating manual computation errors — a certified best practice.

Anchor project structure for solana development

After anchor init, you get:

my-program/
├── programs/
│   └── my-program/...
├── tests/
│   └── my-program.ts
├── app/
├── migrations/
├── Anchor.toml
└── package.json

Anchor.toml is the central config. It stores program addresses, cluster, and wallet. For local development, use solana-test-validator:

solana-test-validator --reset
# in a separate terminal:
anchor test --skip-local-validator

IDL and client integration for anchor framework

The main value of Anchor is automatic IDL generation. Based on the IDL, a TypeScript client is generated — guaranteed zero manual serialization errors:

import { Program, AnchorProvider } from "@coral-xyz/anchor";
import { MyProgram, IDL } from "./target/types/my_program";
const provider = AnchorProvider.env();
const program = new Program<MyProgram>(IDL, provider);
await program.methods.initialize(new BN(1000))
  .accounts({ myAccount: ..., user: ..., systemProgram: ... })
  .signers([myAccountKp])
  .rpc();

This eliminates manual serialization and deserialization — a major source of errors in native Solana.

Testing with Anchor for solana test validator

Tests are written in TypeScript using Mocha, built into Anchor. anchor test compiles the program, starts a localnet, deploys, and runs tests. For complex scenarios, use bankrun or solana-program-test. Bankrun runs tests without a full validator, speeding iterations 5-10x. Example test:

import * as anchor from "@coral-xyz/anchor";
describe("my-program", () => {
  it("initializes", async () => {
    const program = anchor.workspace.MyProgram as Program<MyProgram>;
    // ...
  });
});

You get test coverage without manually starting a validator.

How to set up CI/CD for Anchor?

We use GitHub Actions with dependency caching. On each commit, the program builds, tests run, and deployment to devnet happens. Build takes under 2 minutes. Example .github/workflows/anchor.yml:

name: Anchor CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - uses: ./.github/actions/setup-anchor
      - run: anchor test

This ensures automatic version compatibility checks on every commit.

Deploy to devnet and mainnet with anchor deploy

For devnet, just anchor deploy --provider.cluster devnet. On mainnet, deploy via solana program deploy ... — always keep the program keypair in cold storage. Losing the keypair means no upgrades. We recommend Squads Protocol for multisig. After deployment, verify with solana-verify so users can check the code. Our certified process ensures deployment in under 2 hours.

What you get from our certified setup

  • Fully configured environment: Anchor, Solana CLI, Rust toolchain, test validator.
  • Sample program with IDL and TypeScript client.
  • Working tests covering key scenarios.
  • CI/CD pipeline for automatic build and deploy.
  • Project documentation and team training.
  • Certification of solana-verify compliance.

Our team has 5+ years of certified Solana experience, 30+ projects on Anchor. For one client, we set up a CI/CD pipeline that cut deployment time from 4 hours to 15 minutes — a guaranteed 16x improvement. If you want to save time and up to $2000, contact us for a turnkey environment setup in 1–2 days. Get a certified consultation: we'll assess your project and suggest the optimal approach.

Anchor framework

Smart Contract Development

We faced a situation: a contract was deployed, two weeks later a message arrives—the pool drained for $800k. Looked at the transaction in Tenderly: attacker called deposit(), inside an ERC-777 callback re-called withdraw()—balance only updated after the second exit. Classic reentrancy, but not via ETH transfer—through an ERC-777 hook. ReentrancyGuard was only on withdraw().

Such cases are not rare. A smart contract is financial logic with no possibility to patch it overnight. Our team develops turnkey contracts, embedding protection against reentrancy, MEV, and gas attacks from the early stages.

How We Develop Smart Contracts Turnkey

We start with business logic audit and stack selection. Solidity 0.8.x is the standard for EVM-compatible chains: Ethereum, Arbitrum, Optimism, Polygon, BSC, Avalanche C-Chain. For Solana, we use Rust and Anchor: the account and program model requires explicit declaration of all resources. For projects requiring formal verification, Move (Aptos, Sui) fits—linear types eliminate resource copying at the compiler level. Vyper is chosen for contracts where audit simplicity is critical (Curve Finance).

Language Execution Model Typical Domain Risks
Solidity 0.8.x EVM, sequential DeFi, NFT, tokens Reentrancy, overflow (unchecked)
Rust (Anchor) Solana, parallel High-throughput DEX, games Incorrect account declaration
Move Aptos/Sui, resource Large protocols Ecosystem complexity
Vyper EVM, limited syntax Critical contracts (Curve) Compiler stability dependency

Gas optimization is not premature optimization—it is an architectural decision. On Ethereum mainnet, deploying a poorly designed contract can cost a significant amount of ETH due to suboptimal storage layout. Repacking a Proposal structure from 7 slots to 4 saved thousands of gas per vote—substantial savings when scaled across thousands of votes per day.

Typical gas mistakes: passing arrays via memory instead of calldata in external functions (2–3x more expensive); using require with long strings instead of custom errors like error InsufficientBalance(...). Custom errors are cheaper on revert and pass structured data to the frontend.

Why Smart Contract Audit Is Critical for Security

Audit is not a one-time check—it is a built-in development stage. We use three levels:

  1. Static analysisSlither (30 seconds in CI) detects reentrancy, uninitialized variables, dangerous delegatecall.
  2. Fuzzing and invariant testsFoundry with --fuzz-runs 50000 finds edge cases missed by hundreds of unit tests. Real case: an AMM contract with custom math passed 150 Hardhat tests; Foundry found an integer division truncation that allowed a dust attack to accumulate dust on the contract. Echidna checks invariants ("sum of all balances ≤ totalSupply").
  3. Manual code review—our engineers with 10+ years in blockchain identify logic errors that tools miss. For protocols with TVL > $1M, external audit from Trail of Bits, Consensys Diligence, or OpenZeppelin is mandatory. Timeline: 2–4 weeks.

Any upgradeable protocol must have a timelock. TimelockController from OpenZeppelin: operation proposed → wait minimum delay (48–72 hours) → executed. Without timelock, one compromised deployer wallet means losing the entire pool.

What Upgrade Patterns Do We Choose?

Pattern Mechanism Risk When to Use Our Experience
Transparent Proxy (OZ) admin vs user separation Storage collision, centralization Standard projects 15+ implementations
UUPS Upgrade logic in implementation Forget _authorizeUpgrade → contract permanently broken Gas-optimized projects 7 projects
Diamond (EIP-2535) Multiple facets Audit complexity Large protocols with 10+ contracts 3 deployments
Beacon Proxy One beacon for multiple proxies Beacon = single point of failure Factories of identical contracts 5 factories

Storage collision is the main danger of proxies. Implementation v2 must not add variables before existing ones. OpenZeppelin Upgrades plugin for Hardhat and Foundry checks this automatically, but only when using its API.

How to Protect a Contract from MEV and Front-Running

On Ethereum mainnet, transactions in the mempool are visible to all. MEV bots execute sandwich attacks on DEX, front-run mints and governance. Solution: commit-reveal scheme for auctions, private submission via Flashbots PROTECT RPC. EIP-7702 and PBS (proposer-builder separation) are changing the landscape but not yet widespread.

What Is the Development Process?

  1. Analysis—functional specification, call diagram, edge case analysis. Without this, coding starts in vain.
  2. Development—Solidity/Rust with tests in parallel. Test → code → refactoring. Use Foundry for fuzz and invariant tests.
  3. Internal audit—Slither + Echidna + manual code review. Foundry invariant tests for protocol invariants.
  4. External audit—for projects with real money. Timeline: 2–4 weeks.
  5. Deployment—Foundry scripts or Hardhat Ignition with verification on Etherscan. Gnosis Safe for ownership transfer immediately after deployment.
  6. Monitoring—Tenderly alerts, OpenZeppelin Defender, Forta Network.

What Is Included

  • Architecture documentation and contract specification (NatSpec).
  • Source code with repository and CI (Slither, Foundry, coverage).
  • Deployed contract with verification on blockchain explorer.
  • Audit results (internal and external upon request).
  • Access to monitoring and management (Gnosis Safe).
  • Code warranty: critical bug fixes within one month after deployment.
  • Consultation on web integration (wagmi, RainbowKit).

Estimated Timelines

  • ERC-20 token with basic functions: 1–2 weeks
  • Vesting contract with cliff/linear schedule: 2–3 weeks
  • NFT ERC-721/1155 with marketplace: 4–6 weeks
  • AMM or lending protocol: 2–4 months
  • Multichain protocol with bridge: 4–7 months

Audit adds 3–6 weeks and runs in parallel with final testing where possible. Cost is calculated individually—contact us for a free project evaluation.

Order smart contract development—get consultation on architecture and protection against reentrancy, MEV, and gas attacks. Want to discuss details? Write to us—we will select the optimal stack for your task.