TypeScript SDK
Hyperliquid has no official TypeScript SDK. Its API docs list two community SDKs, nktkas/hyperliquid and nomeida/hyperliquid. This guide covers the first (npm: @nktkas/hyperliquid). A guide for the second follows once it is tested.
The change
Section titled “The change”HttpTransport takes apiUrl: “Custom API URL for info and exchange requests”.
const transport = new HttpTransport();const transport = new HttpTransport({ apiUrl: "http://127.0.0.1:8547" });const wallet = privateKeyToAccount(API_WALLET_KEY);const wallet = privateKeyToAccount(GUARD_CLIENT_KEY);Full example
Section titled “Full example”import { ExchangeClient, HttpTransport, InfoClient } from "@nktkas/hyperliquid";import { privateKeyToAccount } from "viem/accounts";
const transport = new HttpTransport({ apiUrl: "http://127.0.0.1:8547" });const wallet = privateKeyToAccount("0x..."); // the client key Guard printed
const info = new InfoClient({ transport });const exchange = new ExchangeClient({ transport, wallet });filled in from your settings ·
The options
Section titled “The options”| Option | Value | Default without Guard |
|---|---|---|
apiUrl | Guard’s URL | https://api.hyperliquid.xyz (mainnet), https://api.hyperliquid-testnet.xyz (testnet) |
isTestnet | match Guard’s network if you like; see below | false |
timeout | leave at the default, or raise it a little | 10_000 ms |
wallet | a viem account from the Guard client key |
Network in the signature. The SDK signs for testnet when isTestnet is true, otherwise for mainnet. Guard is planned to accept either and to sign the real order for its own network (why it is safe).
WebSocket. The SDK’s WebSocket transport is separate. Use it against Hyperliquid directly for market data, or wait for Guard’s WebSocket pass-through.