A simple Solana escrow smart contract project built with Anchor to learn the basics of Solana smart contracts and Rust.
- Written in Rust using the Anchor framework
- Basic escrow logic: initialize and withdraw instructions
- TypeScript tests using Vitest
- Example of SOL airdrop and account setup
- Modern React UI using Material UI (MUI) and Solana Wallet Adapter
- Rust
- Solana CLI
- Node.js (v18+ recommended)
- Anchor CLI
-
Clone the repository
git clone <this-repo-url> cd sol_escrow
-
Install dependencies
npm install
-
Install Anchor CLI
cargo install --git https://github.com/coral-xyz/anchor --tag v0.31.1 anchor-cli --locked
-
Start the Solana test validator
Open a new terminal window and run:
solana-test-validator
-
Set up your Solana keypairs for test validator
In a separate terminal, generate wallets for each role:
solana-keygen new --outfile ~/.config/solana/initializer.json solana-keygen new --outfile ~/.config/solana/taker.json
Then fund each wallet using the test validator:
solana airdrop 5 ~/.config/solana/initializer.json --url localhost solana airdrop 5 ~/.config/solana/taker.json --url localhost
If the airdrop hangs
solana-test-validator --reset
You can switch between wallets for CLI commands like this:
solana config set --keypair ~/.config/solana/initializer.json
Or use the
--keypairflag for one-off commands:solana balance --keypair ~/.config/solana/taker.json -
Configure Solana to use localnet
solana config set --url localhost -
Build and deploy the program
anchor build anchor deploy
-
Run tests
npm testor
npx vitest run
How to Create All Necessary Wallets for Development
You may want multiple wallets for testing different roles (e.g., initializer, taker). Here’s how to create and manage them:
Generate a new wallet for each role:
solana-keygen new --outfile ~/.config/solana/initializer.json
solana-keygen new --outfile ~/.config/solana/taker.jsonMake sure your local validator is running, then fund each wallet:
solana airdrop 5 ~/.config/solana/initializer.json --url localhost
solana airdrop 5 ~/.config/solana/taker.json --url localhostOr, to airdrop by address:
solana airdrop 5 <WALLET_ADDRESS> --url localhostGet the address with:
solana-keygen pubkey ~/.config/solana/initializer.jsonSet the active wallet for CLI commands:
solana config set --keypair ~/.config/solana/initializer.jsonOr use --keypair for one-off commands:
solana balance --keypair ~/.config/solana/taker.jsonIn Node.js/TypeScript:
const { Keypair } = require("@solana/web3.js");
const fs = require("fs");
const secret = JSON.parse(fs.readFileSync("/path/to/initializer.json"));
const keypair = Keypair.fromSecretKey(Uint8Array.from(secret));If you want to use these wallets in Phantom/Brave:
- Open the wallet extension, choose "Import Private Key," and paste the array from your
.jsonfile.
- The UI is located in the
sol-escrow-uifolder. - Built with React and Material UI (MUI) for modern, responsive components.
- Uses Solana Wallet Adapter for wallet connection and transaction signing.
- Key UI packages:
@mui/material@emotion/react@emotion/styled@solana/wallet-adapter-react@solana/wallet-adapter-wallets@solana/wallet-adapter-react-ui@solana/web3.js@coral-xyz/anchor
cd sol-escrow-ui
npm install
npm run devThen open http://localhost:5173 in your browser.
programs/sol-escrow/- Rust smart contract (Anchor program)tests/sol-escrow.test.ts- TypeScript integration teststarget/idl/sol_escrow.json- Generated IDL for the programsol-escrow-ui/- React frontend UI
- If you see warnings about deprecated methods or Node module types, they can usually be ignored for learning and local development.
- For more information on Anchor, see the Anchor Book.

