Hyperliquid is a high-performance blockchain designed specifically for decentralized derivatives trading. It offers incredibly fast transaction processing, low fees, and a fully onchain open financial system.This guide will walk you through setting up trading on Hyperliquid using Privy’s EVM wallets, focusing on how to securely authenticate and interact with the Hyperliquid API without ever exposing private keys.
The Privy SDKs are designed to be fully compatible with the Hyperliquid API, allowing you to build secure trading applications with ease.
Use the ethers signer to initialize the Hyperliquid client:
Copy
Ask AI
import * as hl from '@nktkas/hyperliquid';// Create Hyperliquid transport and clientconst transport = new hl.HttpTransport();const client = new hl.ExchangeClient({ transport, wallet: signer});const infoClient = new hl.InfoClient({ transport })
Before trading, ensure the wallet has an account on Hyperliquid:
Copy
Ask AI
// Check if Hyperliquid account is activeconst preTransferCheck = await infoClient.preTransferCheck({ user: wallet.address, source: "<address-used-to-credit-account>",});if (!preTransferCheck.userExists) { throw new Error("Hyperliquid account does not exist for this wallet.");}
Now you can use the client to place orders and interact with the Hyperliquid API:
Copy
Ask AI
// Place a market orderconst orderResponse = await client.order({ orders: [ { a: btcIndex, // Asset index b: true, // Buy order s: sz, // Size r: false, // Not reduce-only p: pxUp, // Price (0 for market order) t: { trigger: { isMarket: true, tpsl: "tp", triggerPx: pxDown } }, // Market order }, ], grouping: "na", // No grouping});console.log("Order placed:", orderResponse);// Check open positionsconst userState = await infoClient.clearinghouseState({ user: address });console.log("Account state:", userState);
This approach keeps your wallet’s private keys secure by delegating all signing operations
to Privy’s secure API, while providing full compatibility with Hyperliquid’s trading features.
By combining Privy’s secure wallet infrastructure with Hyperliquid’s high-performance trading platform, you can build powerful trading applications without compromising on security. The custom signer approach allows you to leverage Privy’s key management while still benefiting from all the features of Hyperliquid’s API.For more advanced features like subscription to real-time order book data or implementing complex trading strategies, refer to the Hyperliquid documentation.
Your application can now securely trade on Hyperliquid using Privy’s managed wallets!