Skip to main content
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 demonstrates how to programmatically access Hyperliquid through Privy’s SDKs, covering essential operations including agent wallet creation, trade execution, subaccount management, and builder code integration for revenue sharing

Prerequisites

Before you begin, make sure you have:
  • A Privy account with an app created
  • Node.js 16+ installed
  • Basic familiarity with TypeScript/JavaScript

Installation

Install the required dependencies:
npm install @nktkas/hyperliquid @privy-io/node viem

Quickstart

Here’s a minimal example to get you started:
import { PrivyClient } from '@privy-io/node';
import { createViemAccount } from '@privy-io/node/viem';
import * as hl from '@nktkas/hyperliquid';

// Initialize Privy client
const privy = new PrivyClient({
  appId: 'insert-your-app-id',
  appSecret: 'insert-your-app-secret',
});

// Create a wallet
const wallet = await privy.wallets().createWallet({
  chain_type: 'ethereum',
});

// Create a viem account
const account = createViemAccount(privy, {
  walletId: wallet.id,
  address: wallet.address as `0x${string}`,
});

// Initialize Hyperliquid client
const transport = new hl.HttpTransport({
  isTestnet: true,
});

const client = new hl.ExchangeClient({
  transport,
  wallet: account,
});

Placing Your First Order

Once you have your client set up, you can place a limit order:
// Place a limit buy order for BTC
const order = await client.order({
  orders: [
    {
      a: 0, // Asset index (0 = BTC)
      b: true, // Buy side (true = buy, false = sell)
      p: '95000', // Limit price in USD
      s: '0.001', // Size (0.001 BTC)
      r: false, // Reduce-only (false = can open new position)
      t: {limit: {tif: 'Gtc'}} // Time in force: Good-til-canceled
    }
  ],
  grouping: 'na' // Order grouping (usually "na")
});

console.log('Order placed:', order);
This example places a buy order for 0.001 BTC at $95,000. The order will remain active until it’s filled or you cancel it. Learn more about different order types and trading patterns in the Trading Patterns guide.

Funding

Deposit to HyperCore

To start trading on Hyperliquid, you need to deposit funds to HyperCore. A minimum of $5 USDC on Arbitrum is required to deposit. Funds will be credited to the address that makes the deposit.
import {encodeFunctionData, parseUnits, erc20Abi} from 'viem';

const HYPERLIQUID_BRIDGE_ADDRESS = '0x2Df1c51E09aECF9cacB7bc98cB1742757f163dF7';
const ARBITRUM_USDC_ADDRESS = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831';

// Deposit USDC from Arbitrum to HyperCore
const transaction = await privy
  .wallets()
  .ethereum()
  .sendTransaction(wallet.id, {
    sponsor: true,
    caip2: 'eip155:42161',
    params: {
      transaction: {
        to: ARBITRUM_USDC_ADDRESS,
        data: encodeFunctionData({
          abi: erc20Abi,
          functionName: 'transfer',
          args: [HYPERLIQUID_BRIDGE_ADDRESS, parseUnits('5', 6)]
        })
      }
    }
  });

console.log(transaction);
Learn more about the Hyperliquid bridge in the official documentation.

Withdraw from HyperCore

To withdraw funds from Hyperliquid back to your wallet, use the withdraw3 method. Funds will be credited to the destination address on Arbitrum as USDC.
// Withdraw USDC from HyperCore to your wallet
const withdraw = await client.withdraw3({
  destination: wallet.address,
  amount: '5'
});

console.log(withdraw);
Withdrawals are User Signed Actions and must be signed by the master wallet. Agent wallets cannot initiate withdrawals directly.

Faucet (Testnet Only)

To use the testnet faucet, your master account must first be activated on mainnet. Send at least $5 USDC on Arbitrum to the bridge address from the master account to activate it. Once activated, you can claim testnet funds by making an API request:
const response = await fetch('https://api.hyperliquid-testnet.xyz/info', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    type: 'claimDrip',
    user: wallet.address
  })
});

const result = await response.json();
console.log(result);
The faucet provides $1000 USDC for testnet trading. You can only claim from the faucet once per address.

View Wallet Activity

You can track all deposits, withdrawals, and trading activity by viewing your wallet on the Hyperliquid explorer:
The explorer shows real-time transaction history, trading positions, and account balances for any Hyperliquid address.

Next Steps

Explore these guides to learn more about building with Hyperliquid and Privy:

Resources

Why Use Privy with Hyperliquid?

  • Security: Private keys never leave Privy’s secure infrastructure
  • Simplicity: No need to manage key storage or rotation
  • Compatibility: Full compatibility with Hyperliquid’s SDK and API
  • Flexibility: Easily create and manage multiple wallets for different strategies
You’re ready to start building secure trading applications on Hyperliquid!