> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# Trade on Hyperliquid

Openfort backend wallets implement viem's signing interface, so they plug directly into the [`@nktkas/hyperliquid`](https://github.com/nktkas/hyperliquid) SDK with no adapter needed.

## Build it with your agent

Adding this to an app you already have? Set up your coding agent with the [Openfort docs MCP server and skill](https://www.openfort.io/docs/overview/building-with-ai), then give it this prompt:

```text
Add Hyperliquid perps trading to this app using Openfort. Follow the "Add this to your app" section of
https://github.com/openfort-xyz/recipes-hub/blob/main/hyperliquid/AGENTS.md
```

The same file lists every Openfort primitive the recipe uses and the errors you're likely to hit, with their fixes.

## Architecture

```text
┌──────────────┐     ┌────────────────┐     ┌──────────────────┐
│  Your server │────▶│ Openfort API   │────▶│ Backend wallet   │
│              │     │ (account mgmt) │     │ (viem signer)    │
└──────────────┘     └────────────────┘     └────────┬─────────┘
                                                     │
                                                     ▼
                                            ┌──────────────────┐
                                            │ @nktkas/hyperliquid│
                                            │  ExchangeClient   │
                                            └────────┬─────────┘
                                                     │
                                                     ▼
                                            ┌──────────────────┐
                                            │   Hyperliquid    │
                                            │   Exchange API   │
                                            └──────────────────┘
```

## Prerequisites

* An Openfort account with API keys ([Sign up](https://dashboard.openfort.io))
* Node.js 22.12+
* `@openfort/openfort-node` and `@nktkas/hyperliquid` installed

```bash
npm install @openfort/openfort-node @nktkas/hyperliquid viem
```

## Quickstart

Create a backend wallet and place your first order.

:::steps
### Create a backend wallet

```ts
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

const account = await openfort.accounts.evm.backend.create()

console.log('Wallet address:', account.address)
```

### Connect to Hyperliquid and place an order

```ts
import * as hl from '@nktkas/hyperliquid'

const transport = new hl.HttpTransport({ isTestnet: true })
const exchange = new hl.ExchangeClient({ wallet: account, transport })
const info = new hl.InfoClient({ transport })

// Fetch mid price for ETH
const allMids = await info.allMids()
const ethMid = Number.parseFloat(allMids['ETH'])

// Place a limit buy 5% below mid
await exchange.order({
  orders: [
    {
      a: 4, // ETH asset index
      b: true, // buy
      p: (ethMid * 0.95).toFixed(1),
      s: '0.01',
      r: false, // not reduce-only
      t: { limit: { tif: 'Gtc' } },
    },
  ],
  grouping: 'na',
})
```
:::

## Fund your wallet

Before trading, your backend wallet needs USDC on Hyperliquid's L1.

### Deposit from Arbitrum

Deposit USDC by sending a plain ERC-20 `transfer` of at least 5 USDC to Hyperliquid's Bridge2 contract on Arbitrum. Bridge2 credits the Hyperliquid account of the address that sent the transfer; smaller deposits are lost. On testnet, the Bridge2 contract on Arbitrum Sepolia (`0x08cfc1B6b2dCF36A1480b99353A354AA8AC56f89`) only credits the USDC2 test token (`0x1baAbB04529D43a73232B713C0FE471f7c7334d5`).

### Withdraw to Arbitrum

```ts
await exchange.withdraw3({
  destination: account.address,
  amount: '50',
})
```

### Testnet faucet

For testnet development, claim mock USDC from the [Hyperliquid testnet faucet](https://app.hyperliquid-testnet.xyz/drip).

## React Native demo

A complete mobile trading application built with Expo and Openfort embedded wallets.

Video: Hyperliquid React Native demo — [https://www.youtube.com/watch?v=AHUlXc8lR\_w](https://www.youtube.com/watch?v=AHUlXc8lR_w)

[View Sample Code](https://github.com/openfort-xyz/recipes-hub/tree/main/hyperliquid) — GitHub Repository. Complete source code for the Hyperliquid trading application with React Native components and trading logic.

## Next steps

* [Agent wallets](https://www.openfort.io/docs/recipes/hyperliquid/agent-wallets) — Delegate trading to agent wallets with time-limited permissions.
* [Executing trades](https://www.openfort.io/docs/recipes/hyperliquid/trading) — Market, limit, stop-loss, TWAP orders, and leverage configuration.
* [Policies](https://www.openfort.io/docs/recipes/hyperliquid/policies) — Restrict signing actions with Openfort's policy engine.
* [HyperEVM](https://www.openfort.io/docs/recipes/hyperliquid/hyperevm) — Deploy contracts and send transactions on HyperEVM.
* [Client-side SDKs](https://www.openfort.io/docs/recipes/hyperliquid/client-side) — Integrate Hyperliquid trading into React and React Native apps.
* [Subaccounts](https://www.openfort.io/docs/recipes/hyperliquid/subaccounts) — Isolate positions and risk with Hyperliquid subaccounts.
* [Builder codes](https://www.openfort.io/docs/recipes/hyperliquid/builder-codes) — Attribute fees and earn revenue from trades.
