Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
Hyperliquid is a high-performance decentralized exchange (DEX) built on Arbitrum that offers perpetual futures trading with deep liquidity and low fees. The Hyperliquid SDK provides a comprehensive TypeScript interface for interacting with the exchange programmatically.
This guide shows you how to integrate the Hyperliquid SDK with Dynamic’s SDK to create trading applications with seamless wallet connectivity.
Prerequisites
Before integrating Hyperliquid with Dynamic, ensure you have:
- Dynamic SDK version v4
- Hyperliquid chain enabled in Dynamic dashboard - Enable the Hyperliquid chain (Chain ID: 999) in your Dynamic dashboard under the EVM chains section
- Hyperliquid SDK installed - We’ll cover this in the installation section
Installation
Install the Hyperliquid SDK in your project:
npm install @nktkas/hyperliquid
yarn add @nktkas/hyperliquid
pnpm add @nktkas/hyperliquid
npx expo install @nktkas/hyperliquid
Creating the Hyperliquid Exchange Client
The Hyperliquid SDK’s ExchangeClient is the main interface for trading operations. It requires a wallet instance that can sign transactions.
Standard EVM Wallet Integration
For standard EVM wallets connected through Dynamic, use the Viem extension to create a wallet client:
import * as hl from '@nktkas/hyperliquid'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
import { isEthereumWallet } from '@dynamic-labs/ethereum';
const useHyperliquidExchangeClientFromDynamicPrimayWallet = async () => {
const { primaryWallet } = useDynamicContext()
const [exchangeClient, setExchangeClient] = useState<hl.ExchangeClient | null>(null)
useEffect(() => {
const createExchangeClient = async () => {
if (!primaryWallet) {
return;
}
if (!isEthereumWallet(primaryWallet)) {
return;
}
const walletClient = await primaryWallet.getWalletClient('999')
const exchangeClient = new hl.ExchangeClient({
transport: new hl.HttpTransport(),
wallet: walletClient,
})
setExchangeClient(exchangeClient)
}
createExchangeClient();
}, [primaryWallet])
}
// Usage example
const usePlaceOrder = () => {
const exchangeClient = useHyperliquidExchangeClientFromDynamicPrimayWallet()
return useCallback(async () => {
try {
if (!exchangeClient) {
throw new Error("Client not loaded");
}
// Example: Place a limit order
const orderResult = await exchangeClient.order({
orders: [{
a: 0, // asset index (0 for ETH)
b: true, // is_buy (true for buy, false for sell)
p: "30000", // price
s: "0.1", // size
r: false, // reduce_only
t: {
limit: {
tif: "Gtc", // time in force
},
},
}],
grouping: "na",
})
console.log('Order placed:', orderResult)
return orderResult
} catch (error) {
console.error('Failed to place order:', error)
throw error
}
}, [exchangeClient]);
}
Smart Wallet Integration
For smart wallets using account abstraction, you need to access the underlying EOA (Externally Owned Account) wallet for signing:
import { useCallback, useEffect, useState } from 'react'
import * as hl from '@nktkas/hyperliquid'
import { useDynamicContext, useSmartWallets } from '@dynamic-labs/sdk-react-core'
import { isEthereumWallet } from '@dynamic-labs/ethereum'
function useHyperliquidClientFromSmartWallet() {
const { primaryWallet } = useDynamicContext()
const { getEOAWallet } = useSmartWallets()
const [exchangeClient, setExchangeClient] = useState<hl.ExchangeClient | null>(null)
useEffect(() => {
const createClient = async () => {
if (!primaryWallet || !isEthereumWallet(primaryWallet)) return
const eoaWallet = getEOAWallet(primaryWallet)
if (!eoaWallet || !isEthereumWallet(eoaWallet)) return
// Optionally request a client for Hyperliquid's chain id (999)
const walletClient = await eoaWallet.getWalletClient('999')
const client = new hl.ExchangeClient({
transport: new hl.HttpTransport(),
wallet: walletClient,
})
if (mounted) setExchangeClient(client)
}
createClient()
}, [primaryWallet])
return exchangeClient
}
// Usage example with smart wallet (React)
export function useGetAccountInfo() {
const exchangeClient = useHyperliquidClientFromSmartWallet()
return useCallback(async () => {
if (!exchangeClient) throw new Error('Client not ready')
const accountInfo = await exchangeClient.getUserState()
return accountInfo
}, [exchangeClient])
}
What You Can Do Next
Once you have created the Hyperliquid exchange client, you can access the full range of trading and account management features:
Trading Operations
- Place Orders: Market orders, limit orders, and stop orders
- Cancel Orders: Cancel individual or all orders
- Modify Orders: Update existing order parameters
For comprehensive documentation on all available methods and parameters, visit the Hyperliquid SDK repository.