Skip to content

Node.js quickstart with JavaScript ​

Install @siebly/hyperliquid-api and retrieve the BTC mid price with one REST request in Node.js. The example is plain JavaScript and needs no TypeScript compiler, wallet or private key.

Installation ​

TypeScript definitions are included.

Install the npm package with your preferred tool:

sh
npm install @siebly/hyperliquid-api
sh
pnpm add @siebly/hyperliquid-api
sh
yarn add @siebly/hyperliquid-api
sh
bun add @siebly/hyperliquid-api
sh
deno add npm:@siebly/hyperliquid-api
text
Package: @siebly/hyperliquid-api
npm: https://www.npmjs.com/package/@siebly/hyperliquid-api

For other npm-compatible tools, use the same package from npm. Runtime-specific setup is covered below.

Choose your setup ​

Follow the guide for your runtime or framework. Each includes a complete project with commands to install dependencies and run it.

SetupGuides
Node.jsJavaScript or TypeScript
Alternative runtimesBun or Deno
Browser appsReact with Vite or Vite with plain JavaScript
Next.jsNode.js server Route Handler
Cloudflare WorkersPublic prices and authenticated orders
Mobile appsReact Native / Expo for iOS and Android

Browser and Expo guides include SDK-specific bundler configuration and polyfills where needed. See Runtime compatibility for tested versions, required configuration and what the checks cover.

Use Node.js 24 for this quickstart. For other runtimes and required polyfills, see Runtime compatibility.

Make a request ​

Save this as prices.mjs in the project where the package is installed.

js
import { RestClient } from '@siebly/hyperliquid-api';

async function main() {
  const client = new RestClient();
  const mids = await client.getAllMids();
  if (mids.BTC === undefined) {
    throw new Error('BTC was not present in the mid-price response.');
  }
  console.log('BTC mid price:', mids.BTC);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run the script:

sh
node prices.mjs

Example output ​

getAllMids() returns a map of coin names to price strings. The script prints the BTC entry, for example:

text
BTC mid price: 65000.5

The request uses Mainnet by default and returns prices as strings.

getAllMids reference · Error handling

For import errors, failed requests or a missing BTC price, see Troubleshooting.

Module formats ​

The .mjs extension tells Node.js to use ES modules and import. For CommonJS, use a .cjs file with const { RestClient } = require('@siebly/hyperliquid-api') and keep the async main() function. The complete Node.js project includes both formats. TypeScript projects can use the same imports and the included type definitions; the Node.js TypeScript guide adds a compiler configuration and build commands.

Choose a client ​

Your taskClient
Make an HTTP request and await the resultRestClient
Receive market data and account updatesWebsocketClient
Make an awaitable request over WebSocketWebsocketAPIClient

Next steps ​

TypeScript integrations ​

The SDK works with both JavaScript and TypeScript. TypeScript is optional, but we strongly recommend it for SDK integrations: the included types help catch invalid method names, parameter shapes and response assumptions at build time, before requests reach the exchange. If you choose TypeScript, follow the TypeScript setup and run npx tsc --noEmit during development and CI. Type checking does not replace runtime validation or exchange-side checks.

Some runtimes can execute TypeScript directly. For example, Node.js type stripping supports erasable TypeScript syntax without a separate compiler, but does not check types. If your runtime cannot execute the syntax used by a TypeScript example, compile that example to JavaScript or use a compatible TypeScript runner. Examples with local .js imports that refer to TypeScript source files can use the compiler-based setup above. Plain JavaScript usage does not need any TypeScript tooling.

See Testnet for setup, credentials and limitations.

Built by Siebly. Open source SDKs for exchange APIs.