examples/web-trading. Read the overview first for who signs what. Markets load as in Showcase markets code, and market below is one HIP4Market from loadEvents.
1
Install
2
Connect the wallet
src/trading.ts
hip4.client.fetchUserRole(address) returns { role: "missing" }, the wallet has no Hyperliquid account yet. The user deposits USDC on Hyperliquid first.3
Enable trading
src/trading.ts
4
Move USDC to spot
Outcome trades use the spot balance. Check when the wallet connects, and offer the move if USDC sits in perps.
src/trading.ts
5
Show the order book
{ price: "0.61", size: "120.0" }.6
Place and cancel orders
builderAddress and builderFee to each order, or pass them to createHIP4Adapter.7
Show the account
src/main.ts.Next steps
- Trading, for every option of
placeOrder,placeOrdersandcancelOrder - Authentication, for how the session key signs