This is the public API/SDK guide for integrators. For internal implementation detail (Orchestrator state machine, signer roles), see docs/guides/escrow.md in the repo.
How blockchain-based escrow works in OFFER-HUB — fund locking, release flows, and dispute handling.
This is the public API/SDK guide for integrators. For internal implementation detail (Orchestrator state machine, signer roles), see docs/guides/escrow.md in the repo.
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.
Make sure you understand the Order Lifecycle before diving into escrow mechanics.
OFFER-HUB uses Trustless Work smart contracts on the Stellar blockchain for non-custodial escrow. This means:
The escrow contract follows the internal Escrow state machine below, generated from ESCROW_TRANSITIONS in packages/shared/src/enums/escrow-status.enum.ts in the orchestrator repository. The order around it follows the Order lifecycle.
Order-level statuses (e.g. ESCROW_CREATING, ESCROW_FUNDING, ESCROW_FUNDED, IN_PROGRESS, CLOSED) belong to the Order state machine. The escrow machine above tracks the smart contract itself.
After reserving funds, create the escrow contract:
Response:
The contract deployment happens asynchronously. Listen for events or poll the order status.
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.
IN_PROGRESSFunding typically takes 5-10 seconds. The order status progresses through ESCROW_FUNDING → ESCROW_FUNDED → IN_PROGRESS.
When the buyer approves the work, release funds to the seller:
Releasing funds requires three separate Stellar transactions signed by different parties:
The seller signs first to mark the milestone as completed, then the buyer signs twice — once to approve and once to trigger the actual fund transfer. All signing happens server-side via the parties' invisible wallets.
Source: apps/api/src/modules/resolution/resolution.service.ts (requestRelease) passes order.sellerId to changeMilestoneStatus, then order.buyerId to approveMilestone and releaseEscrow; apps/api/src/providers/trustless-work/clients/escrow.client.ts maps those to the change-milestone-status, approve-milestone and release-funds contract functions, each requiring the matching role (serviceProvider, approver, releaseSigner) defined in apps/api/src/providers/trustless-work/types/trustless-work.types.ts.
A refund is requested by the buyer — directly, or after either party opens a dispute (openedBy accepts BUYER or SELLER, per DisputeOpenedBy in packages/shared/src/enums/dispute-status.enum.ts).
After review, the platform resolves the dispute:
Source: apps/api/src/modules/resolution/resolution.service.ts (requestRefund) — the first XDR is signed with the buyer's wallet, the second with the platform wallet configured by PLATFORM_USER_ID; the contract functions dispute-escrow and resolve-dispute live in apps/api/src/providers/trustless-work/clients/escrow.client.ts. Opening a dispute itself (POST /orders/{id}/resolution/dispute) writes the DISPUTED status only — disputeEscrow is submitted as part of the refund.
Disputes require platform intervention. The smart contract won't transfer funds until the platform signs the resolveDispute transaction as disputeResolver.
Role separation is enforced on-chain. The disputeResolver must be a different party from the disputer. Because the buyer signs step 1, only the platform wallet — never the buyer or seller — can sign the resolution (step 2). This prevents either party from unilaterally reclaiming funds.
The SDK simplifies escrow operations:
OFFER-HUB tracks two types of balances:
Stored in the database for fast operations:
Actual USDC in the user's Stellar wallet:
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.
The platform wallet is a special Stellar account that:
Configure it in your environment:
Blockchain transactions can take time. Handle timeouts gracefully:
Escrow lifecycle events are delivered over the SSE event stream at GET /api/v1/events — there is no outbound webhook API:
Or with the SDK:
See Events (SSE) for the full event catalog, connection parameters, and replay support.
GET /api/v1/events; there is no outbound webhook API