Anchor Guide

Complete guide to deploy your Anchor escrow program

Environment Setup

Install required tools and dependencies

Install Rust

Install Rust programming language

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install Solana CLI

Install Solana command line tools

sh -c "$(curl -sSfL https://release.solana.com/v1.18.4/install)"

Install Anchor

Install Anchor framework CLI

npm install -g @coral-xyz/anchor-cli
Configuration Files

Essential configuration files for your project

Anchor.toml
[features]
resolution = true
skip-lint = false

[programs.devnet]
escrow = "11111111111111111111111111111112"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "devnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
package.json
{
  "scripts": {
    "lint:fix": "prettier */*.js "*/**/*{.js,.ts}" -w",
    "lint": "prettier */*.js "*/**/*{.js,.ts}" --check"
  },
  "dependencies": {
    "@coral-xyz/anchor": "^0.29.0"
  },
  "devDependencies": {
    "@types/bn.js": "^5.1.0",
    "@types/chai": "^4.3.0",
    "chai": "^4.3.4",
    "mocha": "^9.0.3",
    "prettier": "^2.6.2",
    "ts-mocha": "^10.0.0",
    "typescript": "^4.3.5"
  }
}
deploy.sh
#!/bin/bash
set -e

echo "🚀 Starting Escrow Program Deployment"

# Build the program
echo "📦 Building program..."
anchor build

# Deploy to devnet
echo "🌐 Deploying to devnet..."
anchor deploy --provider.cluster devnet

# Get program ID
PROGRAM_ID=$(solana address -k target/deploy/escrow-keypair.json)
echo "✅ Program deployed with ID: $PROGRAM_ID"

# Update Anchor.toml with new program ID
sed -i "s/escrow = ".*"/escrow = "$PROGRAM_ID"/" Anchor.toml

echo "🎉 Deployment complete!"
echo "Program ID: $PROGRAM_ID"
echo "Cluster: devnet"
echo "Explorer: https://explorer.solana.com/address/$PROGRAM_ID?cluster=devnet"
Quick Start Commands

Copy and paste these commands to get started quickly

Development

anchor init escrow-program
cd escrow-program
anchor build
anchor test

Deployment

solana config set --url devnet
solana airdrop 2
anchor deploy
solana program show <PROGRAM_ID>
Common Issues & Solutions

Build Errors

Run cargo clean and rebuild

Insufficient SOL

Request more SOL: solana airdrop 2

Program ID Mismatch

Update Anchor.toml with the correct program ID after deployment