A Solana smart contract (program) for creating and managing token escrows, built with Anchor. This project demonstrates a minimal, production-ready escrow flow with full test coverage.
- Create an escrow account with custom SPL Token mints
- Deposit tokens into a vault (PDA)
- Refund and close escrow, returning tokens to the maker
- Uses SPL Token 2022 and Anchor's CPI features
- Comprehensive TypeScript test suite
- Clone the repo:
git clone https://github.com/tenrikut/Q3-25-Anchor-Escrow.git cd anchor-escrow - Install dependencies:
yarn install
- Build the program:
anchor build
- Configure Solana CLI:
solana config set --url http://127.0.0.1:8899 solana-keygen new --no-bip39-passphrase --force --outfile ~/.config/solana/id.json solana airdrop 5
- Start the local validator:
solana-test-validator --reset
- Deploy the program:
solana program deploy target/deploy/anchor_escrow.so --program-id target/deploy/anchor_escrow-keypair.json
- Run the tests:
ANCHOR_PROVIDER_URL=http://127.0.0.1:8899 ANCHOR_WALLET=~/.config/solana/id.json yarn test
anchor-escrow/
├── programs/anchor-escrow/ # Rust smart contract
│ ├── src/
│ └── Cargo.toml
├── tests/ # TypeScript tests
│ └── anchor-escrow.ts
├── migrations/ # Anchor migrations
├── Anchor.toml # Anchor config
├── package.json # JS/TS dependencies
├── README.md
└── ...
programs/anchor-escrow/src/lib.rs— Main program logic and instruction handlerstests/anchor-escrow.ts— MVP test suite for escrow creation, refund, and error handling
- Create Escrow:
- Call the
makeinstruction with your parameters
- Call the
- Refund Escrow:
- Call the
refundinstruction to close and reclaim tokens
- Call the
MIT License