> ## Documentation Index
> Fetch the complete documentation index at: https://docs.outcome.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Outcome HIP-4 SDK: outcomes on Hyperliquid

> A typed TypeScript SDK for building on HIP-4 - fetch markets, stream live data, place orders, run conversion primitives, and manage USDH funds on Hyperliquid.

`@outcome.xyz/hip4` — a modular stack of HIP-4 & its financial primitives.

```bash theme={null}
pnpm add @outcome.xyz/hip4
```

<div className="hero-frame">
  <img src="https://mintcdn.com/outcomelabs/6iSXuMAWvMPrcKSw/images/sdk-architecture.svg?fit=max&auto=format&n=6iSXuMAWvMPrcKSw&q=85&s=d5dfcd1b4ba6577daed4ef5b61ee818f" alt="HIP-4 SDK stack: outcome.xyz consumes the SDK, which composes six sub-adapters atop a single HIP-4 client" width="1124" height="694" data-path="images/sdk-architecture.svg" />
</div>

## Key features

<CardGroup cols={2}>
  <Card title="Market discovery" icon="search" href="/sdk/guides/fetch-markets">
    Fetch and filter prediction markets by type (`defaultBinding`, `labelledBinding`, `priceBucket`), category, or status. Paginate results and group by type or parent question.
  </Card>

  <Card title="Real-time data" icon="activity" href="/sdk/guides/real-time-data">
    Subscribe to live order books, mid prices, and trade streams via WebSocket. The SDK handles connection management and auto-reconnect with exponential backoff.
  </Card>

  <Card title="Order trading" icon="arrow-left-right" href="/sdk/guides/trading">
    Place limit and market orders with tick-aligned pricing, min-notional validation, and optional builder fee configuration. Cancel resting orders by ID.
  </Card>

  <Card title="Fund management" icon="wallet" href="/sdk/guides/wallet-funding">
    Deposit USDC to your prediction account, buy USDH, and withdraw funds back to your wallet. Uses EIP-712 signing for transfers and L1 agent signing for spot trades.
  </Card>
</CardGroup>

## Architecture

The SDK is organized around a single `HIP4Client` that handles HTTP routing, 5xx retry logic, and WebSocket connection management. Six sub-adapters wrap that client and expose domain-specific methods:

| Adapter                 | Property          | Responsibility                        |
| ----------------------- | ----------------- | ------------------------------------- |
| `HIP4EventAdapter`      | `hip4.events`     | Market discovery and event listing    |
| `HIP4MarketDataAdapter` | `hip4.marketData` | Order books, prices, trades, candles  |
| `HIP4AccountAdapter`    | `hip4.account`    | Positions, balances, open orders      |
| `HIP4TradingAdapter`    | `hip4.trading`    | Place and cancel orders               |
| `HIP4Auth`              | `hip4.auth`       | Agent key approval and auth state     |
| `HIP4WalletAdapter`     | `hip4.wallet`     | USDH deposits, withdrawals, transfers |

You create the adapter with `createHIP4Adapter()` and call `initialize()` once to warm up the event cache. After that, all sub-adapters are accessible as properties on the returned object.

```typescript theme={null}
import { createHIP4Adapter } from "@outcome.xyz/hip4";

const hip4 = createHIP4Adapter({ testnet: true });
await hip4.initialize();

// All sub-adapters are now ready
const markets = await hip4.events.fetchMarkets();
const book    = await hip4.marketData.fetchOrderBook("516", 0);
const status  = hip4.auth.getAuthStatus();
```

<Note>
  The SDK has zero runtime dependencies. All signing - including L1 agent signing (MessagePack + keccak-256 + EIP-712) and user-signed EIP-712 operations - is implemented from scratch in TypeScript with no third-party libraries.
</Note>

<Note>
  Both testnet and mainnet are supported. Pass `{ testnet: true }` (the default) to target the Hyperliquid testnet, or `{ testnet: false }` for mainnet. The SDK automatically routes REST and WebSocket connections to the correct endpoints.
</Note>
