A decentralized escrow platform built on the Solana blockchain to facilitate secure transactions between freelancers and clients. This project uses Anchor for the Solana program and Next.js for the frontend interface.
frontend/: Next.js application for the user interfacesolana-program/: Anchor-based Solana program
This repository contains the on-chain Escrow program (EscrowProtocol) written in Rust using Anchor. It provides trustless, PDA-backed escrows for freelance payments so clients and freelancers can transact with confidence.
EscrowProtocol makes freelance payments easy by locking funds on-chain until the agreed work is approved. It reduces scams and disputes by providing transparent on-chain history, automated timeout refunds, and a clear approval workflow. Built for Solana with Anchor, the program is designed for low fees and fast confirmations.
The program facilitates trustless transactions between clients and freelancers by holding funds in escrow until work is completed and approved. The system includes dispute resolution mechanisms and timeout protections for both parties.
- Program ID:
HWkW19PFehhdgfkGPHnTQTnfhcCQhMqokqGx3Vav7a3N - Network: Solana Devnet
- Framework: Anchor
- Language: Rust
- Escrow Creation: Clients can create escrow accounts with specified amounts and freelancer addresses
- Fund Deposit: Secure deposit of SOL into the escrow account
- Work Submission: Freelancers can submit work links for client review
- Approval System: Clients can approve submitted work
- Payment Release: Approved payments are released to freelancers
- Dispute Resolution: Either party can initiate disputes
- Refund Mechanism: Automatic refunds for disputed or timed-out escrows
- PDA-based Escrow Accounts: Deterministic addresses using client and freelancer public keys
- Authorization Checks: Only authorized parties can perform specific actions
- Status Validation: State machine prevents invalid transitions
- Timeout Protection: Automatic refunds after specified timeout periods
- Input Validation: Comprehensive validation of all inputs
- Initialize: Client creates escrow with amount, freelancer address, and timeout period
- Fund: Client deposits the agreed amount into the escrow
- Submit: Freelancer submits completed work with a link
- Approve: Client reviews and approves the submission
- Withdraw: Freelancer withdraws the payment
- Dispute: Either party can initiate a dispute for manual resolution
- Refund: Client receives refund in case of disputes or timeouts
Pending: Escrow created, awaiting fundingFunded: Funds deposited, awaiting work submissionSubmitted: Work submitted, awaiting client approvalApproved: Work approved, awaiting payment withdrawalComplete: Payment withdrawn, escrow finishedDisputed: Dispute initiated, requires resolutionRefunded: Funds returned to client
pub struct EscrowAccount {
pub client: Pubkey, // Client's public key
pub freelancer: Pubkey, // Freelancer's public key
pub amount: u64, // Escrow amount in lamports
pub status: EscrowStatus, // Current escrow state
pub work_link: String, // Submitted work link
pub bump: u8, // PDA bump seed
pub created_at: i64, // Creation timestamp
pub funded_at: i64, // Funding timestamp
pub submitted_at: i64, // Work submission timestamp
pub approved_at: i64, // Approval timestamp
pub completed_at: i64, // Completion timestamp
pub disputed_at: i64, // Dispute initiation timestamp
pub refunded_at: i64, // Refund timestamp
pub dispute_timeout_days: u8, // Timeout period in days
}Creates a new escrow account.
- Parameters:
amount,freelancer,dispute_timeout_days - Signer: Client
- Accounts: Client, EscrowAccount (init), SystemProgram
Deposits funds into the escrow.
- Signer: Client
- Accounts: Client, EscrowAccount, SystemProgram
Submits completed work for review.
- Parameters:
work_link - Signer: Freelancer
- Accounts: Freelancer, EscrowAccount
Approves submitted work.
- Signer: Client
- Accounts: Client, EscrowAccount
Withdraws payment after approval.
- Signer: Freelancer
- Accounts: Freelancer, EscrowAccount, SystemProgram
Initiates a dispute.
- Signer: Client
- Accounts: Client, EscrowAccount
Processes refund for disputed or timed-out escrows.
- Signer: Client
- Accounts: Client, EscrowAccount, SystemProgram
The program emits events for all major state changes:
EscrowInitializedFundsDepositedWorkSubmittedSubmissionApprovedPaymentWithdrawnDisputeInitiatedClientRefunded
- Rust 1.70+
- Solana CLI 1.16+
- Anchor Framework 0.31+
- Node.js 16+
anchor buildanchor test --skip-local-validatoranchor deploy --provider.cluster devnetprograms/capstone_freelance_escrow/src/
├── lib.rs # Main program entry point
├── state.rs # Account structures and enums
├── errors.rs # Custom error definitions
├── events.rs # Event definitions
└── instructions/ # Instruction handlers
├── mod.rs
├── initialize_escrow.rs
├── deposit_funds.rs
├── submit_work.rs
├── approve_submission.rs
├── withdraw_payment.rs
├── initiate_dispute.rs
└── refund_client.rs
The program includes comprehensive error handling for:
- Invalid status transitions
- Unauthorized access attempts
- Insufficient funds
- Invalid parameters
- Timeout violations
- All state transitions are validated
- Only authorized signers can perform actions
- PDA seeds ensure deterministic account addresses
- Input validation prevents malicious data
- Timeout mechanisms prevent indefinite locks
- Node.js (v18 or higher)
- pnpm
- Rust (latest stable)
- Solana CLI tools
- Anchor framework
git clone <repository-url>
cd freelance_escrowcd frontend
pnpm installcd ../solana-program
pnpm installEnsure you have a Solana wallet and are connected to the desired network (devnet for testing).
solana config set --url https://api.devnet.solana.com
solana-keygen new # if you don't have a walletcd solana-program
anchor build
anchor deployNote the program ID from the deployment output. Update the frontend configuration if necessary.
Update the program ID and other constants in frontend/utils/constants.ts if needed.
cd frontend
pnpm devThe application will be available at http://localhost:3000.
- Connect your Solana wallet using the wallet interface.
- Create an escrow by specifying the recipient, amount, and conditions.
- The escrow holds funds until conditions are met.
- Release or dispute funds as appropriate.
cd solana-program
anchor testcd frontend
pnpm testanchor build --provider.cluster mainnet-beta
anchor deploy --provider.cluster mainnet-betaBuild and deploy the Next.js app to your preferred hosting service (Vercel, Netlify, etc.).
cd frontend
pnpm build- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
This project is licensed under the MIT License.