Skip to content
LogoLogo

JavaScript and TypeScript

@hyperjutsu/hyperliquid is a drop-in replacement for your Hyperliquid client based on nktkas/hyperliquid. It handles signing internally.

Install

npm install @hyperjutsu/hyperliquid viem

Examples use a Viem owner or approved-agent wallet.

Create your clients

Use your signing key and API URL:

import {
  ExchangeClient,
  HttpTransport,
  InfoClient,
  SubscriptionClient,
  WebSocketTransport,
} from '@hyperjutsu/hyperliquid'
import { privateKeyToAccount } from 'viem/accounts'
 
const wallet = privateKeyToAccount(privateKey)
const transport = new HttpTransport({ apiUrl })
const info = new InfoClient({ transport, wallet })
const exchange = new ExchangeClient({ transport, wallet })

Use a verified transport. These examples use mainnet; set isTestnet: true on both transports for testnet.

Read your account

Use the account owner's address, including when an agent signs:

const orders = await info.openOrders({ user: accountAddress })
const account = await info.clearinghouseState({ user: accountAddress })

The SDK signs private queries automatically.

Place an order

const result = await exchange.order({
  orders: [{
    a: 0,
    b: true,
    p: '100000',
    s: '0.001',
    r: false,
    t: { limit: { tif: 'Gtc' } },
    c: '0x11111111111111111111111111111111',
  }],
  grouping: 'na',
})

Use valid market values and a new CLOID for each new order. Inspect each child result.

Subscribe and trade over WebSocket

const socket = new WebSocketTransport({ url: wsUrl })
const subscriptions = new SubscriptionClient({ transport: socket, wallet })
const wsExchange = new ExchangeClient({ transport: socket, wallet })
 
const subscription = await subscriptions.openOrders({ user: accountAddress }, (data) => {
  console.log(data.orders)
})
 
await wsExchange.cancel({ cancels: [{ a: 0, o: 12345 }] })
await subscription.unsubscribe()

Cancel using an order ID from your account. The SDK signs and renews subscriptions. After a disconnect, reconcile state and uncertain orders before submitting replacements.

Switch from @nktkas/hyperliquid

Update your imports:

-import { ExchangeClient, InfoClient, HttpTransport } from '@nktkas/hyperliquid'
+import { ExchangeClient, InfoClient, HttpTransport } from '@hyperjutsu/hyperliquid'

Keep method calls. Configure the Hyperjutsu transport and pass wallet to all three clients.

API coverage · Raw API · Custom signing