When using direct method imports, ensure you pass the correct configuration object as the first argument based on the API type:
Info methods
Use InfoClient configuration (e.g., { transport }).
Exchange methods
Use ExchangeClient configuration (e.g., { transport, wallet }).
Subscription methods
Use SubscriptionClient configuration (e.g., { transport }) and provide a callback function as the second argument.
Explorer methods
Use ExplorerClient configuration (e.g., { transport }).
// Info method example
import { HttpTransport } from "@nktkas/hyperliquid";
import { allMids } from "@nktkas/hyperliquid/api/info";
const transport = new HttpTransport();
const result = await allMids({ transport });
// Exchange method example
import { HttpTransport } from "@nktkas/hyperliquid";
import { order } from "@nktkas/hyperliquid/api/exchange";
import { privateKeyToAccount } from "viem/accounts";
const transport = new HttpTransport();
const wallet = privateKeyToAccount("0x...");
await order(
{ transport, wallet },
{
orders: [{
a: 0,
b: true,
p: "50000",
s: "0.01",
r: false,
t: { limit: { tif: "Gtc" } },
}],
grouping: "na",
},
);
// Subscription method example
import { WebSocketTransport } from "@nktkas/hyperliquid";
import { allMids } from "@nktkas/hyperliquid/api/subscription";
const transport = new WebSocketTransport();
const subscription = await allMids({ transport }, (data) => {
console.log(data.mids);
});
// Explorer method example
import { HttpTransport } from "@nktkas/hyperliquid";
import { blockDetails } from "@nktkas/hyperliquid/api/explorer";
const transport = new HttpTransport();
const block = await blockDetails({ transport }, { height: 123 });