FairPay is a transparent, trustless freelance platform built on blockchain technology. This project implements a comprehensive escrow system with milestone-based payments, dispute resolution mechanisms, and organization management to create a fair and secure environment for both employers and freelancers.
Unlike traditional freelance platforms that charge high fees and rely on centralized dispute resolution, FairPay utilizes smart contracts to automate payments, enforce agreed-upon terms, and provide an immutable record of work agreements and delivery.
- Features
- Technical Implementation
- How It Works
- Installation
- Deployment
- Testing
- Security
- Contributing
- License
- Decentralized Escrow: Secure funds in smart contracts until work is completed and verified
- Milestone-based Payments: Break projects into manageable milestones with individual deadlines and payments
- Multi-token Support: Pay with ETH or any ERC20 token
- Organization Management: Create and manage teams with multiple members
- Dispute Resolution System: Fair mechanism for resolving disagreements between parties
- Minimal Platform Fees: Transparent fee structure with lower costs than traditional platforms
- Job Assignment: Secure worker assignment and confirmation process
- Full Transparency: All terms, milestones and payments recorded on-chain
- Automatic Payouts: Immediate payment release when milestones are approved
FairPay uses a modular architecture with the following key contracts:
+---------------+
| |
| FairPayCore |
| |
+-------+-------+
|
+---------------+---------------+
| | |
+---------v---------+ +---v---+ +---------v---------+
| | | | | |
| OrganizationManager| | JobFactory | | FeesManager |
| | | | | |
+---------+---------+ +---+---+ +-----------------+
| |
| +-----v------+
| | |
| | JobEscrow |
| | |
+---------+------------+
Here's how the key components interact:
- FairPayCore is the central hub that coordinates all other contracts
- JobFactory creates new JobEscrow contracts when employers request new jobs
- JobEscrow instances manage individual job agreements between employers and workers
- OrganizationManager tracks company/team structures and member permissions
- FeesManager handles platform fee calculations and collection
The JobEscrow contract is the heart of the FairPay system:
contract JobEscrow is ReentrancyGuard, Initializable {
enum JobStatus { Created, InProgress, Completed, Cancelled }
enum MilestoneStatus { NotStarted, InProgress, Completed, Disputed }
address public platform;
address public employer;
address public worker;
JobStatus public status;
struct Milestone {
string title;
string description;
uint256 amount;
uint256 deadline;
MilestoneStatus status;
}
Milestone[] public milestones;
// Additional state variables...
}Each JobEscrow instance:
- Is initialized with job parameters from the JobFactory
- Holds the full payment amount in escrow
- Tracks milestone completion and status
- Enforces access controls (only employer/worker can perform certain actions)
- Manages dispute resolution processes
- Automatically distributes payments when milestones are approved
When a new job is created through FairPayCore, the flow is:
- FairPayCore calls JobFactory's
createJob()function - JobFactory uses JobEscrowFactory to deploy a new JobEscrow contract
- JobEscrow is initialized with job parameters (employer, payment terms, etc.)
- The new JobEscrow address is registered in FairPayCore
- The employer deposits funds into the JobEscrow contract
- The assigned worker confirms acceptance of the job terms
- FairPayCore registers the job-worker relationship
The payment flow works as follows:
- Employer creates a job and deposits the full payment amount
- Worker accepts the job and terms
- Work begins on the first milestone
- Worker completes milestones and submits for review
- Employer approves each milestone, triggering automatic payment
- In case of disputes, a resolution process is initiated
- Platform fees are automatically deducted from each payment
function approveMilestone(uint256 _index) external onlyEmployer jobActive nonReentrant {
// Verification logic
uint256 amount = milestones[_index].amount;
uint256 fee = amount * platformFee / 10000;
IERC20(token).safeTransfer(worker, amount - fee);
IERC20(token).safeTransfer(platform, fee);
}- Create an Organization: Set up your team with a name and description
- Add Team Members: Invite collaborators to join your organization
- Create Jobs: Post work opportunities with detailed requirements
- Fund Escrow: Deposit payment for the entire project
- Set Milestones: Define project phases with deadlines and payment allocation
- Assign Workers: Select qualified freelancers for your projects
- Review Work: Approve completed milestones to release payments
- Browse Available Jobs: Find work opportunities matching your skills
- Review Terms: Examine job details, milestones, and payment terms
- Confirm Jobs: Accept assignments to begin work
- Complete Milestones: Work through project phases according to specifications
- Submit Work: Present completed milestones for approval
- Receive Payments: Get paid automatically when work is approved
- Build Reputation: Establish a verifiable on-chain work history
- Node.js >= 14.0.0
- Yarn >= 1.22.0
- Foundry (forge, anvil, cast)
- Clone the repository
git clone https://github.com/jerrymusaga/fair-pay.git
cd fair-pay- Install dependencies
yarn installforge script script/Deploy.s.sol:DeployScript \
--rpc-url <RPC_URL> \
--private-key <DEPLOYER_PRIVATE_KEY> \
--broadcastRun tests using Foundry:
forge testThe FairPay contracts implement several security mechanisms:
- Access Control: Uses OpenZeppelin's Ownable for admin functions
- Reentrancy Protection: Guards against reentrancy attacks with ReentrancyGuard
- Input Validation: Thorough validation of all input parameters
- SafeERC20: Proper handling of token transfers
- State Management: Careful tracking of job states to prevent exploitation
- Error Handling: Custom errors for gas-efficient reverts
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ for the decentralized freelance ecosystem