Prerequisites
- Node.js 18 or higher (for the built-in
fetchandWebSocket) @nktkas/hyperliquidandvieminstalled (npm install @nktkas/hyperliquid viem)- Reliable Hyperliquid RPC endpoint (sign up for free)
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.
HttpTransport— request/response over HTTP. Used byInfoClientandExchangeClient.WebSocketTransport— persistent connection forSubscriptionClient.
Reading market data
Start with theInfoClient. No wallet, no signing — just data:
Wallets and signing
Write actions must be signed. nktkas does not ship its own key handling — you pass a viem or ethers account as thewallet, and the SDK signs each action for you.
Placing and managing trades
Give anExchangeClient a transport and a wallet, then call action methods:
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 theWebSocketTransport 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 asapiUrl:
- Trading stays on the public API.
apiUrlroutes both/infoand/exchange, but nodes do not serve/exchangeactions — so keep yourExchangeClienton 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
infomethods (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 returnsFailed to deserialize the JSON body into the target type.
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 intry/catch. Successful actions still carry a status you should check:
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.
Related resources
- Hyperliquid tooling — SDKs and APIs at a glance
- Hyperliquid methods — which methods run on your node vs the public API
- Authentication guide — sign and authenticate exchange actions
- Debugging signature errors — agent wallets and chain-mismatch fixes
- Order precision — tick and lot sizing rules
- Building a copy trading bot — a full WebSocket application
- API reference — the complete Hyperliquid API