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:
npm install @siebly/hyperliquid-apipnpm add @siebly/hyperliquid-apiyarn add @siebly/hyperliquid-apibun add @siebly/hyperliquid-apideno add npm:@siebly/hyperliquid-apiPackage: @siebly/hyperliquid-api
npm: https://www.npmjs.com/package/@siebly/hyperliquid-apiFor 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.
| Setup | Guides |
|---|---|
| Node.js | JavaScript or TypeScript |
| Alternative runtimes | Bun or Deno |
| Browser apps | React with Vite or Vite with plain JavaScript |
| Next.js | Node.js server Route Handler |
| Cloudflare Workers | Public prices and authenticated orders |
| Mobile apps | React 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.
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:
node prices.mjsExample output
getAllMids() returns a map of coin names to price strings. The script prints the BTC entry, for example:
BTC mid price: 65000.5The 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 task | Client |
|---|---|
| Make an HTTP request and await the result | RestClient |
| Receive market data and account updates | WebsocketClient |
| Make an awaitable request over WebSocket | WebsocketAPIClient |
Next steps
- Read an order book or candle history.
- Stream prices over WebSocket.
- Choose a network and configure request timeouts.
- Read account state and configure a signer.
- Configure retries, recovery and shutdown for production.
- Follow the full Hyperliquid JavaScript tutorial on Siebly.io.
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.