Make sure you understand the Order Lifecycle before diving into escrow mechanics.
Escrow Guide
How blockchain-based escrow works in OFFER-HUB — fund locking, release flows, and dispute handling.
Escrow is the core security mechanism in OFFER-HUB. When a buyer pays for a service, funds are locked in a Stellar smart contract until the work is delivered and approved. Neither party can unilaterally access the funds — the contract enforces fair resolution.
How Escrow Works
OFFER-HUB uses Trustless Work smart contracts on the Stellar blockchain for non-custodial escrow. This means:
- Funds are on-chain — Not in OFFER-HUB's database
- Contract enforces rules — Release requires proper signatures
- Transparent — Anyone can verify escrow state on Stellar
- Non-custodial — OFFER-HUB cannot access funds without proper authorization
Escrow Participants
| Role | Description |
|---|---|
| Buyer | Deposits funds into escrow |
| Seller | Receives funds when work is approved |
| Platform | OFFER-HUB's signer for dispute resolution |
| Arbiter | Trustless Work's contract for on-chain enforcement |
Escrow Lifecycle
State Machine
State Descriptions
| State | Description |
|---|---|
ESCROW_CREATING | Smart contract being deployed |
ESCROW_CREATED | Contract ready, waiting for funding |
ESCROW_FUNDING | USDC transfer to contract in progress |
ESCROW_FUNDED | Funds locked, work can begin |
IN_PROGRESS | Seller is working on the order |
RELEASING | Release transaction in progress |
DISPUTING | Dispute transaction in progress |
DISPUTED | Awaiting resolution |
CLOSED | Funds released to seller |
REFUNDED | Funds returned to buyer |
Creating Escrow
After reserving funds, create the escrow contract:
Response:
The contract deployment happens asynchronously. Listen for events or poll the order status.
Funding Escrow
Once the contract is created, fund it with USDC:
This triggers an on-chain USDC transfer from the buyer's invisible wallet to the escrow contract.
What Happens During Funding
- Debit buyer's balance — Reserved funds become locked
- Sign transaction — Platform signs with buyer's encrypted key
- Submit to Stellar — USDC sent to contract address
- Confirm on-chain — Wait for ledger confirmation
- Update status — Order becomes
IN_PROGRESS
Funding typically takes 5-10 seconds. The order status progresses through ESCROW_FUNDING → ESCROW_FUNDED → IN_PROGRESS.
Releasing Funds
When the buyer approves the work, release funds to the seller:
The 3-Transaction Release Flow
Releasing funds requires three separate blockchain transactions:
| Step | Transaction | Signer |
|---|---|---|
| 1 | complete_escrow | Buyer approves work |
| 2 | release_escrow | Platform authorizes release |
| 3 | Claim funds | Seller receives USDC |
Release Response
Refunding (Dispute Flow)
If there's a problem, the buyer can request a refund through the dispute process:
Step 1: Open Dispute
Step 2: Platform Resolves
After review, the platform resolves the dispute:
The 2-Transaction Refund Flow
| Step | Transaction | Signer |
|---|---|---|
| 1 | dispute_escrow | Buyer opens dispute |
| 2 | resolve_dispute | Platform refunds buyer |
Disputes require platform intervention. The smart contract won't release funds until the platform signs the resolution transaction.
Using the SDK
The SDK simplifies escrow operations:
Listening to Escrow Events
On-Chain vs Off-Chain Balance
OFFER-HUB tracks two types of balances:
Off-Chain Balance
Stored in the database for fast operations:
- Available — Can be used for new orders or withdrawn
- Reserved — Locked for pending orders (before escrow funding)
On-Chain Balance
Actual USDC in the user's Stellar wallet:
Balance Flow During Escrow
| Stage | Available | Reserved | On-Chain |
|---|---|---|---|
| Initial | 100.00 | 0.00 | 100.00 |
| After reserve | 50.00 | 50.00 | 100.00 |
| After funding | 50.00 | 0.00 | 50.00 (in escrow) |
| After release | 50.00 | 0.00 | 50.00 |
When escrow is funded, the reserved amount leaves both the off-chain balance AND the on-chain wallet. It's now in the smart contract.
Platform Wallet
The platform wallet is a special Stellar account that:
- Co-signs transactions — Required for release/refund
- Collects fees — Platform fees are sent here
- Never holds user funds — Only signs, doesn't custody
Configure it in your environment:
Error Handling
Common Escrow Errors
| Error | Cause | Solution |
|---|---|---|
ESCROW_ALREADY_EXISTS | Duplicate creation attempt | Check order status first |
ESCROW_NOT_FUNDED | Trying to release unfunded escrow | Fund the escrow first |
INVALID_STATE_TRANSITION | Wrong order state | Follow the state machine |
INSUFFICIENT_FUNDS | Wallet doesn't have enough USDC | Check balance before funding |
CONTRACT_ERROR | Stellar contract failure | Check Trustless Work status |
Handling Timeouts
Blockchain transactions can take time. Handle timeouts gracefully:
Webhooks for Escrow Events
Subscribe to escrow lifecycle events:
See Webhooks for payload formats and signature verification.
Security Considerations
- Never expose private keys — All signing happens server-side
- Verify webhook signatures — Prevent spoofed events
- Use idempotency keys — Prevent duplicate funding
- Monitor contract state — Cross-check with Stellar explorer
Next Steps
- Disputes Guide — Handle disagreements
- Withdrawals Guide — Move funds off-platform
- SDK Reference — Full SDK documentation