Frontend integration
A useful frontend should mirror the state machine rather than show every action at once.
Client flow
- Call
createEscrow. - Approve the selected ERC-20 token to the escrow contract.
- Call
fundEscrow. - Wait for
WorkDeliveredor read the escrow state. - Call
approveWork.
It is of utmost importance that the interface separates token approval from escrow funding. They are distinct transactions.
Freelancer flow
- Discover escrows assigned to the connected wallet.
- Wait until the escrow is
Funded. - Call
deliverWork. - Wait for client approval.
- Read
getUserBalance(freelancer, token). - Call
withdraw.
Status-aware actions
| Status | Client | Freelancer |
|---|---|---|
Created | Approve token + fund | Wait |
Funded before deadline | Wait | Deliver |
Funded after deadline | Refund or wait | Deliver |
Delivered | Approve | Wait |
Approved | — | Withdraw credited balance |
Refunded | — | — |
Token decimals
The contract expects base units. A frontend must convert human-readable values using the token's decimals before sending transactions.
Error handling
Handle custom errors, wallet rejection, insufficient token balance, insufficient allowance, network mismatch, and token-originated reverts separately. Do not collapse all failures into “Transaction failed.”