Complete guide to the order lifecycle - from creation to settlement.
Note
This is the public API/SDK guide for integrators. For internal implementation detail (Orchestrator state machine, signer roles), see docs/guides/orders.md in the repo.
Orders are the core of OFFER-HUB. They represent a transaction between a buyer and seller, with funds protected by escrow until work is completed.
Order Lifecycle
Every order follows a strict state machine — the same canonical diagram used across the docs, matching docs/architecture/state-machines.md in the orchestrator repository exactly:
Mermaid
Rendering diagram…
Note
The escrow contract itself follows a separate internal Escrow state machine while the order machine above advances in parallel.
Creating an Order
Basic Order
bash
curl -X POST http://localhost:4000/api/v1/orders \
-H "Authorization: Bearer ohk_live_..." \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 550e8400-e29b-41d4-a716-446655440006" \
-d '{
"buyerId": "usr_buyer123",
"sellerId": "usr_seller456",
"amount": "100.00",
"currency": "USD",
"title": "Logo Design",
"description": "Design a modern logo for my tech startup"
}'
With SDK
typescript
const order = await sdk.orders.create({
buyerId: 'usr_buyer123',
sellerId: 'usr_seller456',
amount: '100.00',
currency: 'USD',
title: 'Logo Design',
description: 'Design a modern logo for my tech startup'
});
For large projects, create one order with multiple milestones. The milestones belong to the same order and share its escrow; they are not separate orders.
Milestone amounts must add up to the total order amount.
Managing Milestones
Milestones are created as part of the parent order. After the order reaches IN_PROGRESS, use the milestone reference to inspect or complete an individual milestone. Completing a milestone updates that milestone within the same order; it does not create a new order or escrow contract.
A milestone can be completed only while its parent order is IN_PROGRESS. Completing all milestones does not replace the order resolution flow; release the order's funds separately.
Reserving Funds
Before creating escrow, reserve the buyer's funds:
bash
curl -X POST http://localhost:4000/api/v1/orders/ord_xyz789/reserve \
-H "Authorization: Bearer ohk_live_..."
This moves funds from available to reserved:
Before
After
available: 100.00
available: 0.00
reserved: 0.00
reserved: 100.00
Creating and Funding Escrow
Create Escrow Contract
bash
curl -X POST http://localhost:4000/api/v1/orders/ord_xyz789/escrow \
-H "Authorization: Bearer ohk_live_..."
This creates a smart contract on Stellar via Trustless Work.
Fund the Escrow
bash
curl -X POST http://localhost:4000/api/v1/orders/ord_xyz789/escrow/fund \
-H "Authorization: Bearer ohk_live_..."
This sends USDC from the buyer's invisible wallet to the smart contract on-chain.
Warning
Funding is irreversible until release or refund. The order status becomes ESCROW_FUNDED, then IN_PROGRESS.
switch (order.status) {
case 'ORDER_CREATED':
// Show "Waiting for funds" UI
break;
case 'FUNDS_RESERVED':
// Show "Creating escrow" UI
break;
case 'IN_PROGRESS':
// Show "Work in progress" UI
break;
case 'DISPUTED':
// Show "Under review" UI
break;
case 'CLOSED':
// Show "Completed" UI
break;
}