Browser wallets

The SDK works with browser extension wallets like MetaMask.

Setup

Connect via a JSON-RPC Accountarrow-up-right:

import { ExchangeClient, HttpTransport } from "@nktkas/hyperliquid";
import { createWalletClient, custom } from "viem";
import { arbitrum } from "viem/chains";

const wallet = createWalletClient({
  chain: arbitrum,
  transport: custom(window.ethereum!),
});

const transport = new HttpTransport();
const client = new ExchangeClient({ transport, wallet });

Signature prompts

Every exchange action triggers a wallet popup that the user must approve. L1 actions (trading and position management) show a phantom agent hash instead of human-readable details — this is by design, because the action is never signed directly.

To avoid repeated popups and hide unreadable L1 signatures from users, approve an agent wallet once with the browser wallet, then use the agent's private key for all subsequent trades:

Last updated