A secure multi-party smart contract system that holds funds in escrow until predefined conditions are met, with built-in dispute resolution mechanisms.
- Multi-party Escrow: Buyer, Seller, and optional Arbitrator roles
- Dispute Resolution: Neutral third-party arbitration system
- Time-lock Protection: Automatic refunds after expiry
- Platform Fees: Configurable fee structure
- Security: Reentrancy guards, access control, emergency pause
contracts/
├── DeScrow.sol # Main escrow contract
├── interfaces/
│ └── IArbitrator.sol # Arbitrator interface
└── libraries/
└── EscrowUtils.sol # Utility functions and structs
- PENDING: Escrow created, awaiting buyer deposit
- FUNDED: Buyer has deposited funds
- IN_DISPUTE: Dispute raised, awaiting arbitrator
- COMPLETED: Funds released to seller
- CANCELLED: Funds returned to buyer
- EXPIRED: Time limit reached, funds automatically returned
const escrowId = await deScrow.connect(buyer).createEscrow(
sellerAddress,
arbitratorAddress,
expiryTimestamp,
{ value: ethers.parseEther("1.0") }
);// Buyer confirms delivery
await deScrow.connect(buyer).confirmDelivery(escrowId);
// Seller requests payment
await deScrow.connect(seller).requestPayment(escrowId);
// Funds automatically released to seller// Either party raises dispute
await deScrow.connect(buyer).raiseDispute(escrowId, "Product not as described");
// Arbitrator resolves dispute
await deScrow.connect(arbitrator).resolveDispute(escrowId, true); // Award to seller// After expiry time passes
await deScrow.connect(buyer).withdrawExpired(escrowId);npm install
npx hardhat compile
npx hardhat test# Deploy to local network
npx hardhat run scripts/deploy.js
# Deploy to testnet
npx hardhat run scripts/deploy.js --network goerli
# Deploy to mainnet
npx hardhat run scripts/deploy.js --network mainnet- All functions include proper access control
- Reentrancy protection on fund transfers
- Input validation on all parameters
- Emergency pause functionality for critical bugs
- Platform fee capped at 10% maximum
- Optimized storage layout
- Minimal external calls
- Efficient event emission
- Library usage for common operations
Run the comprehensive test suite:
npx hardhat testTest coverage includes:
- Happy path scenarios
- Dispute resolution flows
- Time-based expiry handling
- Edge cases and error conditions
- Security attack vectors
MIT License