Get started with the OFFER-HUB TypeScript SDK in minutes.
The OFFER-HUB SDK provides a type-safe TypeScript client for integrating with the Orchestrator API. It handles authentication, retries, and provides typed errors for better error handling.
const order = await sdk.orders.create({
buyer_id: 'usr_buyer123',
seller_id: 'usr_seller456',
amount: '100.00',
currency: 'USD',
title: 'Logo Design',
description: 'Design a logo for my startup'
});
console.log('Order ID:', order.id); // ord_xyz789
console.log('Status:', order.status); // ORDER_CREATED
Complete a Milestone
Milestones are part of one order. List them with sdk.orders.getMilestones() and complete one by its milestone_ref using sdk.orders.completeMilestone() after the order reaches IN_PROGRESS:
// 1. Reserve funds
await sdk.orders.reserve(order.id);
// 2. Create escrow on blockchain
await sdk.orders.createEscrow(order.id);
// 3. Fund the escrow
await sdk.orders.fundEscrow(order.id);
// 4. Release to seller when work is done
await sdk.orders.release(order.id, 'Work completed');
Available Resources
The SDK provides access to all Orchestrator resources:
// Create SDK instance with idempotency key
const idempotentSdk = sdk.withIdempotencyKey(
'550e8400-e29b-41d4-a716-446655440000'
);
// This request can be safely retried
const order = await idempotentSdk.orders.create({
buyer_id: 'usr_buyer',
seller_id: 'usr_seller',
amount: '100.00',
title: 'Service'
});
If you retry with the same idempotency key, you get the same response without creating a duplicate.
The key must be a UUID v4. It is optional, applies to POST, PUT, and
PATCH requests, and is scoped to the API key and request body. A replayed
response includes Idempotency-Replay: true; a different body with the same
key returns 409 IDEMPOTENCY_KEY_REUSED.
Error Handling
The SDK provides typed errors for precise error handling:
typescript
import {
InsufficientFundsError,
NotFoundError,
ValidationError,
InvalidTransitionError,
OfferHubError
} from '@offerhub/sdk';
try {
await sdk.orders.reserve('ord_123');
} catch (error) {
if (error instanceof InsufficientFundsError) {
console.error(`Need ${error.required}, have ${error.available}`);
} else if (error instanceof NotFoundError) {
console.error(`${error.resourceType} not found`);
} else if (error instanceof ValidationError) {
console.error('Validation errors:', error.errors);
} else if (error instanceof InvalidTransitionError) {
console.error(`Cannot transition from ${error.currentState}`);
} else if (error instanceof OfferHubError) {
console.error('API error:', error.message);
}
}
TypeScript Support
The SDK is fully typed. You get autocomplete and type checking:
typescript
import type { User, Order, Balance } from '@offerhub/sdk';
async function processOrder(user: User): Promise<Order> {
const balance: Balance = await sdk.balance.get(user.id);
if (parseFloat(balance.available) < 100) {
throw new Error('Insufficient funds');
}
return sdk.orders.create({
buyerId: user.id,
sellerId: 'usr_seller',
amount: '100.00',
title: 'Service'
});
}
Next Steps
Users Reference - User creation and AirTM linking (sdk.users)