Skip to main content
@nktkas/hyperliquid is the community-favorite TypeScript SDK for Hyperliquid: full HyperCore API coverage, end-to-end type safety, and support for every major JS runtime. This guide walks through building with it against a Chainstack Hyperliquid endpoint — reading market data, signing and placing trades, and streaming real-time updates.
Prerequisites

The mental model: three clients, two transports

The SDK splits along two axes — what you do and how you connect. The clients (the “what”):
  • InfoClient — read-only market and account data (no wallet needed).
  • ExchangeClient — write actions: place and cancel orders, transfers, leverage, and more (needs a wallet to sign).
  • SubscriptionClient — real-time streams over WebSocket.
The transports (the “how”):
  • HttpTransport — request/response over HTTP. Used by InfoClient and ExchangeClient.
  • WebSocketTransport — persistent connection for SubscriptionClient.
You compose them: pick a client, give it a transport. Everything below follows that pattern.

Reading market data

Start with the InfoClient. No wallet, no signing — just data:
Every method is fully typed, so your editor autocompletes parameters and response fields. See the Hyperliquid API reference for the complete method list.

Wallets and signing

Write actions must be signed. nktkas does not ship its own key handling — you pass a viem or ethers account as the wallet, and the SDK signs each action for you.
Hyperliquid has two signing schemes — L1 actions (orders, cancels) and user-signed actions (transfers, withdrawals). nktkas picks the right one per method automatically, so you rarely think about it. When you do need the details, see Signing overview, L1 action signing, and user-signed actions.
For production frontends, use an agent wallet (API wallet): the user approves it once from their browser wallet, then your app signs all trades with the agent key — no chain-mismatch prompts. See debugging signature errors for the pattern.

Placing and managing trades

Give an ExchangeClient a transport and a wallet, then call action methods:
The asset index (a) comes from the info.meta() universe — its position in the array. Prices and sizes are strings, and Hyperliquid enforces strict tick and lot precision; rounding wrong gets the order rejected. See order precision for the rules.

Real-time data

For live data, swap to the WebSocketTransport and a SubscriptionClient. Each subscription takes a callback that fires on every update:
SubscriptionClient also exposes trades, userFills, userEvents, candle, bbo, and webData2. For a full real-time application built on these streams, see building a copy trading bot.

Using your Chainstack node

By default, every transport points at the public Hyperliquid API. To route reads through your own Chainstack Hyperliquid node, pass its endpoint as apiUrl:
Two things to know, both driven by what the open-source Hyperliquid node implements:
  • Trading stays on the public API. apiUrl routes both /info and /exchange, but nodes do not serve /exchange actions — so keep your ExchangeClient on the default (public) transport. Trades are signed locally and submitted to Hyperliquid either way.
  • Some reads are public-only. Your node serves a large subset of HyperCore info methods (meta, clearinghouseState, spotMeta, openOrders, and more); others (allMids, l2Book, metaAndAssetCtxs, candleSnapshot, userFills, …) are only on the public API. The Hyperliquid methods table marks exactly which is which — a public-only method against your node returns Failed to deserialize the JSON body into the target type.
Where your Chainstack node shines is HyperEVM: the full eth_* JSON-RPC surface (plus WebSocket subscriptions and debug/trace) runs on your dedicated endpoint. That side is standard EVM tooling — use viem or ethers pointed at your endpoint rather than the HyperCore SDK above. See Hyperliquid tooling and the API reference.
Pass isTestnet: true to a transport (new HttpTransport({ isTestnet: true })) to target Hyperliquid testnet instead of mainnet.

Error handling

The SDK throws on transport failures and on unsuccessful API responses, so wrap actions in try/catch. Successful actions still carry a status you should check:
A common error is Provided chainId ... must match the active chainId ... when signing from a browser wallet — see debugging signature errors.

Summary

The nktkas SDK gives you three composable clients — InfoClient, ExchangeClient, and SubscriptionClient — over HTTP and WebSocket transports, with viem/ethers wallets for signing. Point reads at your Chainstack node for the HyperCore methods it serves and for all of HyperEVM, keep trading on the public API, and stream live data over WebSocket. From here, the copy-trading, TWAP, and funding-rate guides build complete strategies on these same primitives.
Last modified on June 24, 2026